Pre-backup preparation

The following script is a template script to be run on each machine immediately prior to the backup. It creates a number of specific backup files in /var/backups, including the following:
  • Boot device MBR
  • Each mysql database as a separate file, and as a complete file.
  • Configuration data for dpkg and debconf, which enables restoration of software.
  • Listings of mounts, disks, and lvm volumes.
The script should be customized for the particular hardware configuration of each machine.

#!/bin/bash
BACKUPDIR=/var/backups
LOG=$BACKUPDIR/$HOSTNAME.systeminfo
MBRDEVICE=/dev/disk/by-path/pci-0000:0e:00.0-scsi-0:2:0:0
SQLPASS=PASSWORD

# Print system information
{
    LINE="============================================================="
    echo -e "\n$HOSTNAME dpkg selections `date`\n$LINE"
    dpkg --get-selections
    echo -e "\n$HOSTNAME partition information `date`\n$LINE"
    blkid
    echo
    df
    echo
    mount -l
    echo
    fdisk -l /dev/sd[a-e]
    echo -e "\n$HOSTNAME lvm information `date`\n$LINE"
    vgdisplay
    echo
    lvdisplay
} > $LOG
# Backup boot device MBR. To restore, do the following:
# dd of=/dev/sda if=mbr.img bs=512 count=1
if [[ -n $MBRDEVICE ]]; then
    dd if=$MBRDEVICE of=$BACKUPDIR/system_boot_drive_mbr.bin bs=512 count=1
fi
# Backs up mysql databases
if [[ -n `which mysqld` ]]; then
    LIST=`mysql -e "show databases" -p$SQLPASS | grep '\|' | grep -v Database`
    for db in $LIST; do
        mysqldump --add-drop-database -uroot -pginger07 $db | lzma > \
            $BACKUPDIR/${db}.sql.lzma
    done
    mysqldump --all-databases -uroot -p$SQLPASS | lzma > \
        $BACKUPDIR/all-databases.sql.lzma
fi

# Packup package installations
if [[ -n `which debconf-get-selections` ]]; then
    aptitude install debconf-utils -y
fi
dpkg --get-selections > $BACKUPDIR/dpkg.selections
debconf-get-selections > $BACKUPDIR/debconf.selections

#else echo "Usage `basename $0` [ pre | post ]"

# NOTE: Package reinstallation can be achieved as follows
# dselect update
# debconf-set-selections < debconfsel.txt
# dpkg --set-selections < myselections
# apt-get -u dselect-upgrade # or dselect install

BackupPC XFS Patch

The following patch resolves some problems resulting in repeated transfers of duplicate data when backing up to XFS filesystems. The patch was adapted from http://tinyurl.com/l9nuqc.

Note that the libio-dirent-perl package should be installed for this patch to be most efficient.

--- usr/share/backuppc/lib/BackupPC/Lib.pm      2009-07-23 13:54:01.000000000 -0500
+++ usr/share/backuppc/lib/BackupPC/Lib.pm.XFS_PATCHED  2009-07-23 13:54:01.000000000 -0500
@@ -485,10 +485,16 @@

     from_to($path, "utf8", $need->{charsetLegacy})
                         if ( $need->{charsetLegacy} ne "" );
-    return if ( !opendir(my $fh, $path) );
+# PATCH FROM http://tinyurl.com/l9nuqc applied here manually:
+    my ($fh);
+    if ( !opendir($fh, $path) ) {
+       print "log ERROR: opendir ($path) failed\n";
+       return;
+    }
     if ( $IODirentOk ) {
         @entries = sort({ $a->{inode} <=> $b->{inode} } readdirent($fh));
-        map { $_->{type} = 0 + $_->{type} } @entries;   # make type numeric
+       map { $_->{type} = 0 + $_->{type}; $_->{type} = undef if
+                 ($_->{type} eq BPC_DT_UNKNOWN); } @entries;
     } else {
         @entries = map { { name => $_} } readdir($fh);
     }
@@ -553,10 +559,16 @@
     return if ( !chdir($dir) );
     my $entries = $bpc->dirRead(".", {inode => 1, type => 1});
     #print Dumper($entries);
+    #print ("log got ",scalar(@$entries)," entries for $dir\n");
     foreach my $f ( @$entries ) {
         next if ( $f->{name} eq ".." || $f->{name} eq "." && $dontDoCwd );
         $param->{wanted}($f->{name}, "$dir/$f->{name}");
-        next if ( $f->{type} != BPC_DT_DIR || $f->{name} eq "." );
+# PATCH FROM http://tinyurl.com/l9nuqc applied here manually:
+        #if ( $f->{type} != BPC_DT_DIR ) {
+       #    print ("log skipping non-directory ", $f->{name},
+       #          " type: ", $f->{type}, "\n");
+       #}
+       next if ( $f->{type} != BPC_DT_DIR || $f->{name} eq "." );
         chdir($f->{name});
         $bpc->find($param, "$dir/$f->{name}", 1);
         return if ( !chdir("..") );
 

BackupPC rsyncd Backups

The instructions on the BackupPC wiki for using rsyncd to backup a local directory are incorrect. To do a rsyncd backup of a local directory, the rsyncd.tmp.conf file should look like the following:
hosts allow = 127.0.0.0/8
uid = root
gid = root
use chroot = yes

[titan]
    path = /mnt/repo/backup/archived/titan_2008-12-17/.
    read only = true

# Note, to run the rsync daemon, use the following command line:
rsync --daemon --config=/etc/rsyncd.tmp.conf --no-detach

The "Rsync Share Name" on the server for the above configuration should be titan without slashes anywhere.

Topic revision: r5 - 23 Feb 2010 - 21:48:35 - RyanEgeland
 
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.