rdiff backup working, but am I doing it correctly?

Ywa

Verified User
Joined
Feb 4, 2010
Messages
37
Location
The Netherlands
Hi everyone,

We've been running rdiff-backup backups for the past few weeks on a few of our DirectAdmin boxes. The storage machine initiates the connection and the backup itself is working perfectly.

However, I was wondering if this is a good way to backup DirectAdmin? Am I missing directories? And is it safe to backup MySQL databases this way?

Command that's ran on the storage server/machine:
Code:
rdiff-backup --remote-schema "ssh -C -p$3 %s rdiff-backup --server" -v5 --print-statistics --no-hard-links --backup-mode --include /usr/local/directadmin --include /var/lib/mysql --include /etc --include /var/named --include /var/spool/virtual --include /var/spool/mail --include /var/www/html --include /home --exclude / backupuser@$2::/ /storage/rdiffbackups/$4

$3 = port
$2 = remote host of machine to backup
$4 = local folder to put backup in

Thanks in advance.
 
Hello,

Everything seems to be OK. But, I don't think it's a good idea to backup MySQL databases in such a way. To backup MySQL first dump the database contents to a file using mysqldump, and then backup that file using rdiff-backup. If you are using incremental backups then turn off compression if possible. Incremental backups do not work well with changing compressed data.
 
Yeah I thought about mysqldump. Is it possible to dump all databases with one command?

Thanks for your help so far.
 
There should be the option --all-databases to add to mysqldump line.

Code:
mysqldump -uUSERNAME -pPASSWORD --all-database > all-db_backup.sql

Regards
 
Great, thanks! I'll try to restore a backup on a separate machine soon, to check if everything works properly.
 
That command will make a single file with all databases.

For restore a single database should be

Code:
mysql -uUSERNAME -pPASSWORD --one-database DB_NAME < all-db.sql

Regards
 
Here is an example of what I use, to backup my server. The rdiff-backup syncs changes to a remote server and purges all but the last 10 days if changes. This prevents my remote backup from getting unmanageably huge. Plus I figure I should know if I need to recover something within 10 days. I also have the $USER use ssh keys to authenticate, so I don't have to supply a password.

The mysql backup runs every night before the rdiff-backup and keeps the last 4 backups around. It also purges binary logs to keep them from growing uncontrollably.

I have used this method for years and have even had to resort to it for restores once or twice and it has always worked for me. Obviously other might have slightly different needs or wants and may do things slightly different, but it does work for me.

The first time running the rdiff-backup would obviously take a long time, but after that, it doesn't take that long to send over only the deltas.

rdiff-backup nightly
Code:
#!/bin/sh

USER=remoteuser
SERVER=remoteserver.com

export PATH=/usr/local/bin:/usr/bin:/bin
EXCLUDES="/aquota.group /aquota.user /backup /bin /dev /initrd /lost+found /media /mnt /proc /sbin /selinux /srv /sys /tmp /usr /var/log /home/admin/admin_backups /home/admin/user_backups /root"
INCLUDES="/usr/share/ssl /usr/lib/apache /usr/local"

for incs in $INCLUDES
do
   RDIFF_OPTS="$RDIFF_OPTS --include $incs"
done
for exclds in $EXCLUDES
do
   RDIFF_OPTS="$RDIFF_OPTS --exclude $exclds"
done

RDIFF_OPTS="$RDIFF_OPTS --override-chars-to-quote '' --include-symbolic-links --exclude-special-files --exclude-other-filesystems --terminal-verbosity 4 $1"

echo "/usr/bin/rdiff-backup $RDIFF_OPTS / $USER@$SERVER::/opt/Backups/"
/usr/bin/rdiff-backup $RDIFF_OPTS / $USER@$SERVER::/opt/Backups/
echo "/usr/bin/rdiff-backup --remove-older-than 10D $USER@$SERVER::/opt/Backups/"
/usr/bin/rdiff-backup --force --remove-older-than 10D $USER@$SERVER::/opt/Backups/
mysql backup nightly
Code:
#!/bin/sh
mypath=/home/admin
backupdate=`date +%y%m%d`
rm ${mypath}/sqlbackup/mysql_dump.sql.bz2
/usr/bin/mysqldump --defaults-extra-file=${mypath}/.backup-creds.cnf --opt --flush-logs --all-databases --quick > ${mypath}/sqlbackup/${backupdate}_dump.sql
/usr/bin/mysql --defaults-extra-file=${mypath}/.backup-creds.cnf -e "PURGE BINARY LOGS BEFORE NOW()\G"
for file in `ls -1 ${mypath}/sqlbackup/*_dump.sql.bz2`
do
    mv $file $file.old
done
count=0
for file in `ls -1t ${mypath}/sqlbackup/*_dump.sql.bz2.old`
do
  ((count+=1))
  if [ $count -gt 3 ]
  then
    rm -f $file
  fi
done
bzip2 ${mypath}/sqlbackup/${backupdate}_dump.sql
rm -f ${mypath}/sqlbackup/*_dump.sql
ln -sf ${mypath}/sqlbackup/${backupdate}_dump.sql.bz2 ${mypath}/sqlbackup/mysql_dump.sql.bz2

${mypath}/.backup-creds.cnf
Code:
[client]
host = localhost
user = root
password = rootpassword
 
Last edited:
Back
Top