Oct
4
Git based Server Backups
One of the thing I have to do as a System Administrator is run Backups. There are many ways to do Backups the only issue I have is it has to be easy and work. There are many commercial Backup systems from EMC2 to Full QNAP, and even Home based FreeNAS Solutions. I find that a Linux server with a USB Hard drive and git works the best… and here to you can set one up too!
Note all my how-to’s are done with debian so… here we go.
First as with all debian OS’s UPDATE IT!
apt-get updateapt-get upgrade
Next install git and rsync:
apt-get install git rsyncAlright.. Now lets setup a folder to use for the storage of the Backups.
mkdir /backups/Now edit /backup.run and add the following lines:
#!/bin/bash cd /backups/ # Backup Linux Server 1rsync -avz –progress –delete root@server1.com:/ /backups/server1/ ### Uncomment the next line and Just keep adding servers!
## Backup Linux Server 2
#rsync -avz –progress –delete root@server2.com:/ /backups/server2/ if [ ! -d “.git” ]; then
git init .
fi git add -A
git commit -m “`date –rfc-3339=seconds`”
git gc
Now chmod it:
chmod 755 /backups.runand now we will need to make a SSH Key for the server.
Run ssh-keygen on your machine, and just hit enter when asked for a password. Next, add the contents of the public key file ( ~/.ssh/id_rsa.pub ) into ~/.ssh/authorized_keys on the server you are going to be backing up (the file should be a chmod of 600).
Now you may run the /backup.run with
/backup.run
Now just set a cronjob to backup automatically.
There you go a full backup system. Watch out for the next blog post where we will make a web frontend for git to view the backups.