backup

Technical Notes

These notes are my personal online notebook of useful commands and "how-to's". You are welcome to make use of them if you find them helpful. They obviously don't come with any warranty! Click on one of the category tags above for the notes in any category.

dd and ddrescue to backup partitions

dd if=/dev/VolGroup00/LogVol00 of=/dev/vg1000/LogVol00
dd if=/dev/VolGroup00/LogVol00 | bzip2 -1 > /data/LogVol00.dd.bz
dd if=/dev/VolGroup00/amfhome | bzip2 -1 > /data/amfhome.dd.bz
dd if=/dev/sdc1 | bzip2 -1 > /data/sdc1_grub.dd.bz
#dd if=/dev/VolGroup00/vm_amfh | bzip2 -1 > /data/vm_amfh.dd.bz
dd if=/dev/VolGroup00/vm_amfh of=/data/vm_amfh.dd

dd if=/dev/VolGroup00/jessica | bzip2 -1 > /data/jessica.dd.bz #20Gb
dd if=/dev/VolGroup00/fred | bzip2 -1 > /data/fred.dd.bz #10Gb

Installing rdiff-backup version 1.2.2 on Ubuntu

Ubuntu Hardy and Intrepid come with older versions or rdiff-backup, but the current stable version (1.2.2) is in the Jaunty repositories. To install it:
Download and install the .deb file from the bottom of this page: http://packages.ubuntu.com/jaunty/utils/rdiff-backup
Install the recommended libraries:
aptitude install python-pylibacl python-pyxattr

Drupal backup script

First it is necessary to create a backup user on the database which has (only) read access to everything. This is because its password will be embedded in the backup script which reduces security. This can be done with:

BKUSR=backup
BKPW=backuppassword
BKDIR=/var/www/dbbackup
mkdir -p $BKDIR
echo "GRANT SELECT, LOCK TABLES ON *.* TO '$BKUSR'@'localhost' IDENTIFIED BY '$BKPW'; FLUSH PRIVILEGES;" | mysql -u root -p

In the backup script, first some variables are set up

BKUSR=backup
BKPW=backuppassword
BKDIR=/var/www/dbbackup
SITE=cfaw.info

Backup LVM-based VM to another computer

#first stop VM
#
lvname=vm_www
lvcreate -L5G -s -n $lvname-snap /dev/VolGroup00/$lvname
#the VM can be re-started now
#turn the snapshop into a file image (optionally gzip it)
#dd if=/dev/VolGroup00/$lvname-snap | bzip2 -9 >/backup/$lvname.dd.bz2
dd if=/dev/VolGroup00/$lvname-snap >/backups/$lvname.img
#remove the snapshot
lvremove -f /dev/VolGroup00/$lvname-snap
#copy to another machine
scp $lvname.img root@jordan:/amf300;
rm -f $lvname.img
#on the other machine, run bzip2 -9 vm_xxxx.img

rdiff-backup strategy

To backup windows using rdiff-backup to another computer, four sub-systems need to be configured:

  1. Install cygwin (including rdiff-backup) on the windows machine
  2. Configure and test rdiff-backup across ssh using manual passwords
  3. Configure public key authentication for passwords
  4. Configure scheduled tasks to run the process automatically

MySQL backup

-create a user (such as backup) with select and lock priviledges for all databases from any host
-set MySQL server configuration to listen on external ports
pw=mybackuppassword
hst=MySQLhost
nice mysqldump -h $hst -u backup -p$pw --compress --add-drop-table --extended-insert -A | gzip -9 >/backups/$hst-$(date +"%Y%m%d").gz

MySQL misc tips

phpMyBackupPro: No simpler backup for MySQL: http://www.linux.com/feature/127811
Tunnel to locally running mysql server using ssh:
http://www.nerdlogger.com/2008/06/tunnel-to-locally-running-mysql-server...
create and setup remote administrator:
first make sure that there are not multiple name@addresses where the user can log in, else every one will have to get permissions separately.
CREATE USER 'andrewfoo'@'192.168.1.%' IDENTIFIED BY 'foomatic';
GRANT ALL ON *.* to 'andrewfoo'@'192.168.1.%' WITH GRANT OPTION;

SSH/SCP without a password

Zimbra backup using LVM and rsync

Syndicate content