Automated Linux Backups utilizing rsync over SSH

I was recently tasked with coming up with a backup solution for our Linux based servers. My solution was to use rsync over SSH to pull the data that we wanted over and then use tar to create daily archives, which we can then pull off the server to some other type of storage media or a remote server.

After creating a Linux server that I would use as the backup server, I setup SSH with a public key exchange.

To do this, I typed “ssh-keygen” on my Linux backup server.

After creating a public key on my Linux backup server, I moved the public key over to the servers that the server would be accessing.

To automate the process, I created a custom perl script.

You will notice that the perl script is pretty simple, but written in a way that it can be easily expanded upon. For example, you might get to the point where keeping up with the @server array is more maintenance than it’s worth. You could easily have the perl script access a MySQL database to pull a list of servers and the directories that needed to be pulled over via rsync. You could also add options so that it automatically put the tar.bz2 archive files onto remote storage or even tape.

To automate the script, save the script in a place like /usr/sbin/linuxbackup.pl and then create a bash script in /etc/cron.daily/ that executes the command “linuxbackup.pl auto”. It’s really pretty simple.

May 16, 2010

Posted In: Linux, Perl Tips, System Administration