Backup Your S!

Even though I knew better, I learned the hard way (and Google Cache saved my bum!) about running as root in production.

If your backup process is manual (whatever type of backup), it’s not good enough.

Let’s learn from my mistakes – automate that stuff:

echo -e ‘#!/bin/sh\n
START=$(date +%s)\n
rsync -avh /usr/local/www/* /mountedbackupdrive/hwcdibak/ \\ \n
FINISH=$(date +%s)\n
echo “total time: $(( ($FINISH-$START) / 60 )) minutes, $(( ($FINISH-$START) % 60 )) seconds”‘>>

This is still a half hearted answer, as I don’t want to get into setting up ssh keys at the moment (so my backup is still not good enough).
You can replace /mountedbackupdrive with user@backupserver:/backupdest once you’ve got them configured.

Here’s may way crazier one that I scrounged together (with help from the internets) years ago for my Centos box (it mimics TimeMachine with hard-links):

[root@STG1 Scripts]# cat
#command line enable
#if [ $# -lt 1 ]; then
# echo “No destination defined. Usage: $0 destination” >&2
# exit 1
#elif [ $# -gt 1 ]; then
# echo “Too many arguments. Usage: $0 destination” >&2
# exit 1

START=$(date +%s)
#command line enable
#rsync -aAXv /* $1 –exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found,/home/*/.gvfs,/var/lib/pacman/sync/*,/home/*/.thumbnails/*,/home/*/.mozilla/firefox/*.default/Cache/*,/home/*/.cache/chromium/*}
#FINISH=$(date +%s)
#echo “total time: $(( ($FINISH-$START) / 60 )) minutes, $(( ($FINISH-$START) % 60 )) seconds”

rsync /* /backup/STG1BAK/$2 \
–archive –hard-links \
–human-readable –inplace –numeric-ids –delete \
–delete-excluded –exclude={/backup/*,/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found,/home/*/.gvfs,/var/lib/pacman/sync/*,/home/*/.thumbnails/*,/home/*/.mozilla/firefox/*.default/Cache/*,/home/*/.cache/chromium/*} \
–link-dest=/backup/STG1BAK/$1 \

FINISH=$(date +%s)
echo “total time: $(( ($FINISH-$START) / 60 )) minutes, $(( ($FINISH-$START) % 60 )) seconds”

combine that with a killer crontab ( ):

[root@STG1 colin]# crontab -l
01 * * * * root /root/Scripts/
[root@STG1 colin]# chkconfig crond on

And you’ve got yourself a decent *local* (turned remote with minimal effort) linux backup solution.

Leave a Reply

Your email address will not be published. Required fields are marked *