Q. How do I make remote backups under Linux? I’ve CentOS 5 Linux server located in remote data center and I’d like to backup it to local or another server?
A. Both Linux / UNIX come with handy tools to make secure remote backups. You can use tool called rsync for automating remote backups of your Linux, UNIX, Windows server, Mac OS X and BSD systems. rsync is a program with many more options and uses the rsync remote-update protocol to greatly speed up file transfers when the destination file is being updated.
Task: Copy files / backup files from remote Linux server
Let us say you would like to backup files from remote server called server.nixcraft.in and directory called /home/vivek to local directory called /backup, type the command as follows on local system:
$ rsync -avz -e ssh email@example.com:/home/vivek/ /backup
You need to supply password for vivek user.
Task: Exclude files from backup
You can also skip few files from backup. Let us say you don't want to backup all C source code file, enter:
$ rsync --exclude '*.cpp' -avz -e ssh firstname.lastname@example.org:/home/vivek/ /backup
Task: Automatic backup using a shell script
SSH always prompts for a password. To automate process via a shell script you need to remove password using SSH key i.e. generate passphraseless keys, enter (type at local system):
$ ssh-keygen -t dsa
When asked for to enter passphrase, just press [ENTER] key twice. Now copy public key to remote server:
$ scp ~/.ssh/id_dsa.pub email@example.com:.ssh/authorized_keys
Now you can login without a password. For more information see - howto setup SSH with DSA public key authentication and RSA key authentication for password less login.
Now create a simple shell script as follows:
$ vi backup.sh
rsync --exclude '*.cpp' --exclude '*.log' -avz -e ssh firstname.lastname@example.org:/home/vivek/ /backup
Setup executable permission using chmod command:
$ chmod +x backup.sh
Use cron to command to backup remote server:
$ crontab -e
Make a backup everyday:
Save and close the file.
- 30 Cool Open Source Software I Discovered in 2013
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012
- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop