A Comprehensive Backup Strategy - Sever and Desktop Combined
It's taken me a few years to refine this, but this is the method I suggest for effectively backing up both your web server and your local machine.
You'll need command line access to your remote server running a flavour of linux, a PC (of course) and an external hard drive big enough to fit your files on and space on your local machine to store backup files.
The philosophy is simple but one point is very important - backup your backups. Never trust a single source, a hard drive can fail, a CD can be pinched, an office can be set on fire. It sounds dramatic but it happens.
Your Server
I have two strategies for backing up my web server, to backup up each customer's files in a way they can access them, and to backup the server. I combine backup methods, so there is a daily incremental backup (only files that are new or have changed are saved) and a full weekly backup.
Backups are run by a custom cron (Crontab) job as follows:
Client Backup
For each client I create a folder in '/home', and inside that create a backup folder
mkdir /home/client1/
mkdir /home/client1/backup/
I then set up 7 cron jobs for each client:
1 1 * * 0 root tar -zcf /home/client1/backup/sun.tgz /home/client1 --exclude=*.tgz >/dev/null 2>&1
1 1 * * 1 root tar -zcf /home/client1/backup/mon.tgz ` find /home/client1 -mtime -1 -type f ! -iname "*.tgz" ` >/dev/null 2>&1
1 1 * * 2 root tar -zcf /home/client1/backup/tue.tgz ` find /home/client1 -mtime -1 -type f ! -iname "*.tgz" ` >/dev/null 2>&1
1 1 * * 3 root tar -zcf /home/client1/backup/wed.tgz ` find /home/client1 -mtime -1 -type f ! -iname "*.tgz" ` >/dev/null 2>&1
1 1 * * 4 root tar -zcf /home/client1/backup/thu.tgz ` find /home/client1 -mtime -1 -type f ! -iname "*.tgz" ` >/dev/null 2>&1
1 1 * * 5 root tar -zcf /home/client1/backup/fri.tgz ` find /home/client1 -mtime -1 -type f ! -iname "*.tgz" ` >/dev/null 2>&1
1 1 * * 6 root tar -zcf /home/client1/backup/sat.tgz ` find /home/client1 -mtime -1 -type f ! -iname "*.tgz" ` >/dev/null 2>&1a
Ok looks hard but I'll break it down.
The first line is a Sunday cron job backing up everything. The other lines are daily runs Monday to Saturday backing up new and changed files.
The first part with the numbers and stars with when the cron job runs. In this example it runs at 0101 on Sunday, Monday, Tuesday and so on.
The second part (tar -zcf...) is the command to create a tar zip file.
The third part ('find ...') looks for all new files and lists them silently. It excludes TGZ files, as there's no point backing up backups.
The final part (>/dev/null) is to make the whole process silent so you don't receive an email each time it runs.
So for each new client, I copy this and run it a minute later i.e.
2 1 * * 0 root tar -zcf /home/client2/backup/sun.tgz /home/client1 --exclude=*.tgz >/dev/null 2>&1
2 1 * * 1 root tar -zcf /home/client2/backup/mon.tgz ` find /home/client1 -mtime -1 -type f ! -iname "*.tgz" ` >/dev/null 2>&1
2 1 * * 2 root tar -zcf /home/client2/backup/tue.tgz ` find /home/client1 -mtime -1 -type f ! -iname "*.tgz" ` >/dev/null 2>&1
2 1 * * 3 root tar -zcf /home/client2/backup/wed.tgz ` find /home/client1 -mtime -1 -type f ! -iname "*.tgz" ` >/dev/null 2>&1
2 1 * * 4 root tar -zcf /home/client2/backup/thu.tgz ` find /home/client1 -mtime -1 -type f ! -iname "*.tgz" ` >/dev/null 2>&1
2 1 * * 5 root tar -zcf /home/client2/backup/fri.tgz ` find /home/client1 -mtime -1 -type f ! -iname "*.tgz" ` >/dev/null 2>&1
2 1 * * 6 root tar -zcf /home/client2/backup/sat.tgz ` find /home/client1 -mtime -1 -type f ! -iname "*.tgz" ` >/dev/null 2>&1a
So you can keep going until you have all clients covered.
Clients can access their backups at any time by access their 'backup' folder.
Overall Server Backup
To backup my server in it entirety, I do something pretty similar.
I create a directory (in this example /backup/) away from the home directories and run something similar.
30 0 * * 0 root tar -zcf /backup/sun.tgz /var/lib/mysql/ /var/spool/ /var/log/ /usr/lib/cgi-bin/ /etc /home --exclude=*.tgz >/dev/null 2>&1
30 0 * * 1 root tar -zcf /backup/mon.tgz ` find /var/lib/mysql/ /var/spool/ /var/log/ /usr/lib/cgi-bin/ /etc /home -mtime -1 -type f ! -iname "*.tgz" ` >/dev/null 2>&1
30 0 * * 2 root tar -zcf /backup/tue.tgz ` find /var/lib/mysql/ /var/spool/ /var/log/ /usr/lib/cgi-bin/ /etc /home -mtime -1 -type f ! -iname "*.tgz" ` >/dev/null 2>&1
30 0 * * 3 root tar -zcf /backup/wed.tgz ` find /var/lib/mysql/ /var/spool/ /var/log/ /usr/lib/cgi-bin/ /etc /home -mtime -1 -type f ! -iname "*.tgz" ` >/dev/null 2>&1
30 0 * * 4 root tar -zcf /backup/thu.tgz ` find /var/lib/mysql/ /var/spool/ /var/log/ /usr/lib/cgi-bin/ /etc /home -mtime -1 -type f ! -iname "*.tgz" ` >/dev/null 2>&1
30 0 * * 5 root tar -zcf /backup/fri.tgz ` find /var/lib/mysql/ /var/spool/ /var/log/ /usr/lib/cgi-bin/ /etc /home -mtime -1 -type f ! -iname "*.tgz" ` >/dev/null 2>&1
30 0 * * 6 root tar -zcf /backup/sat.tgz ` find /var/lib/mysql/ /var/spool/ /var/log/ /usr/lib/cgi-bin/ /etc /home -mtime -1 -type f ! -iname "*.tgz" ` >/dev/null 2>&1
The only real difference is what I'm backing up - I'm backing up what I consider to be important things, which are mysql, system mail files, log files, stats files, plus settings and my client's files
Server > Desktop Backup
To enable me to restore should my server fail, every morning I run a FTP job to pull off the latest /backup files and save them to my local desktop machine. I do this manually, I support the idea that this could be do automatically using a service in Windows but it suits me for now.
Desktop Backup
Backing up my local machine is a little simpler. My main tactic is using an External Hard Drive, which means if things go very bad I still have everything on HD from which I can restore my work.
Soft and Hard Backups
My first Backup routine is using the inbuilt Windows backup to run every day at 12. I call this 'soft' as it is controlled by Windows and I just let it get on with that. I like it because it integrates with the operating system, so you can restore old files from multiple points, but I don't like it because I'm weary of trusting a single method in backing up.
My second backup involves using the splendidly simple Karen's Replicator. Download and install, and create a backup routine for every area of your filesystem which is important to your External HD.
The software does what it says - it replicates an area of your Hard Drive on another Hard Drive, or in this case my External Drive. It's a very silent method of doing this backup.
For me, I take a copy of my Server backups (see above), and then important folders in groups. Everyone will have different areas of importance, these are mine. I set it to run daily, and when I go home I unplug my HD and take it home. Note the word Replicate - it deletes files off the External HD if they no longer exist. But as I already backup using the 'soft' method I don't have a problem with that.
Thus using this method I double backup my web server, download the main backup to my local machine, then backup my local machine and the server backup to an External HD. So at any one point, I have a copy of everything somewhere.
I know this isn't perfect (backups are to 24 hours out depending on their time) and only allows for restoration up to a week, but I do believe it covers the basic angles for 'the rest of us' using basic commands, free software and a low-cost external HD in a manner that doesn't take too much time up each day, in fact a few minutes at most.


Loading...
Thanks for dropping by and browsing our website. We hope you found something to interest you amongst all the geekness and techy speak.