1

I have Ubuntu 12.10 installed running a LAMP stack for a small site I host. I need to set up a system for weekly backups of the /var/www directory where all of my sites are. What is the best possible way of doing this?

1

2 Answers 2

2

rsync can do this and can also automatically append a timestamp to your backup files. You can also put a rsync command straight into cron. As an example for a daily backup:

@daily rsync -ab --suffix=_`date +%F` -R {server}:/var/wwww /home/backups/

(this assumes you can already access this machine and that /home/backups/ exists and you also need to change {server} to the system where the files are)

The links posted in comments uses this as an example but has a better method end result: a backup script that you use from cron.

1

The best means is always a matter of taste. I'd prefer using rdiff or rsync over ssh. Just ask, if you need further assistance on any step. This method allows you to place the backup target machine to internal network, so anyone hacking your site can not access your backups.

  1. Setup backup account on the www server, create the public + private ssh keys without a password for that account. Copy the public key to ~backup/.ssh/id_rsa.pub, do not leave the private key on that server.
  2. Add the backup account to www group (or whatever is the primary group of the account running Apache.
  3. Modify /etc/ssh/sshd_config to allow crypto key logins.
  4. On the target machine, setup the backup account and copy the id_rsa and optionally id_rsa.pub to ~backup/.ssh/
  5. Test the connection from the backup target machine and accept the host key: su backup; ssh backup@your-www-server.
  6. Create the backup script to run via cron on the target machine, simplistic example below.
  7. Enhance the script to your taste (or find a better one, the sole purpose of this one is to give you the idea). This one will fill your target drive.
  8. Also remember to backup your database (maybe mysqldump?) and the server configuration.
 
#!/bin/bash
DATE=$(date -I)
FROMDIR=backup@your-www-server/var/www/
TODIR=/var/backup/your-www-server/${DATE}/
LOGDIR=/var/backup/your-www-server/log/

mkdir -p ${TODIR} ${LOGDIR}
rsync -av ${FROMDIR} ${TODIR} >${LOGDIR}/${DATE}.log 2>${LOGDIR}/${DATE}.err
 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .