Code and file examples for the Sys Admin Magazine articles. I could break these apart and make a tar file that installs them, but these are only examples. If you want to start with these as a template, I suggest you change machine names globally in this file, and then tease them apart with your text editor. -- Keith Lofstrom ========================================================================= Part 2 code examples for Sys Admin February 2005 article Version 1.0 January 22, 2005 KHL Do not copy exactly! You will need to modify these for your own system. ========================================================================= Make the dirvish directories: -------------------------------------------------------------------------- #!/bin/bash cd /backup/dirvish for i in boot usr home root do mkdir -p mom/mom-$i/dirvish done mkdir -p dick/dick-root/dirvish mkdir -p jane/jane-root/dirvish mkdir -p jane/jane-home/dirvish chmod -R 700 /backup/ -------------------------------------------------------------------------- /backup/dirvish/jane/jane-root/dirvish/default.conf -------------------------------------------------------------------------- client: jane tree: / xdev: true index: gzip image-default: %Y-%m%d-%H%M exclude: /proc/ /mnt/ isoimage *.iso /var**/tmp/ /var/*/*.oldlog -------------------------------------------------------------------------- /etc/master.conf -------------------------------------------------------------------------- bank: /backup/dirvish/mom /backup/dirvish/dick /backup/dirvish/jane exclude: lost+found/ Runall: jane-home 03:00 jane-root 03:00 dick-root 03:00 mom-home 03:00 mom-usr 03:00 mom-root 03:00 mom-boot 03:00 expire-default: never # keep the Sunday backups forever, the dailies for 3 months expire-rule: # MIN HR DOM MON DOW STRFTIME_FMT * * * * * +3 months * * * * 1 never pre-server: /usr/local/sbin/dirvish-pre post-server: /usr/local/sbin/dirvish-post -------------------------------------------------------------------------- /usr/local/sbin/dirvish-post -------------------------------------------------------------------------- #!/bin/bash # /usr/local/sbin/dirvish-post SFDISK='/sbin/sfdisk -d /dev/hdmain ' DF='/bin/df ' SSH='/usr/bin/ssh' # variables # DIRVISH_CLIENT provided from dirvish # DIRVISH_DEST provided from dirvish $SSH $DIRVISH_CLIENT $DF > $DIRVISH_DEST/../df.out $SSH $DIRVISH_CLIENT $SFDISK > $DIRVISH_DEST/../sfdisk.out exit 0 -------------------------------------------------------------------------- /usr/local/sbin/dirvish-daily -------------------------------------------------------------------------- #!/bin/bash # /usr/local/sbin/dirvish-daily # this is called by /etc/cron.daily/backup PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin /sbin/hdparm -zb 1 /dev/backup /bin/mount /dev/backup /backup /usr/local/sbin/dirvish-runall /bin/umount /dev/backup /sbin/hdparm -b 0 /dev/backup exit 0 -------------------------------------------------------------------------- /usr/cron.daily/slocate.cron -------------------------------------------------------------------------- #!/bin/sh # /usr/cron.daily/slocate.cron renice +19 -p $$ >/dev/null 2>&1 /usr/bin/updatedb -f "nfs,smbfs,ncpfs,proc,devpts" \ -e "/tmp,/var/tmp,/usr/tmp,/afs,/net,/backup" -------------------------------------------------------------------------- /usr/local/sbin/dirvish-init -------------------------------------------------------------------------- #!/bin/bash # /usr/local/sbin/dirvish-init DIRV="/usr/local/sbin/dirvish --init --vault" $DIRV mom-root $DIRV mom-boot $DIRV mom-home $DIRV mom-usr $DIRV dick-root $DIRV jane-root $DIRV jane-home exit 0 -------------------------------------------------------------------------- /etc/cron.daily/backup -------------------------------------------------------------------------- #!/bin/bash # /etc/cron.daily/backup, run dirvish /usr/local/sbin/dirvish-daily -------------------------------------------------------------------------- ========================================================================= Part 3 code examples for Sys Admin March 2005 article Version 1.0 January 22, 2005 KHL Do not copy exactly! You will need to modify these for your own system: ========================================================================= restore the file fum.c ---------------------------------------------------------------------- #!/bin/bash src=/backup/dirvish/jane/jane-home/2005-0305-0300/tree/fgump/src/foo/fum.c des=jane:/home/fgump/src/foo/fum.c rsync -vvrltHpgoDx --backup --numeric-ids $src $dst ---------------------------------------------------------------------- restore the directory foo ---------------------------------------------------------------------- #!/bin/bash src=/backup/dirvish/jane/jane-home/2005-0305-0300/tree/fgump/src/foo des=jane:/home/fgump/src rsync -vvrltHpgoDx --backup --numeric-ids $src $dst ---------------------------------------------------------------------- restore the directory foo to directory 2005-0305-0300 ---------------------------------------------------------------------- #!/bin/bash src=/backup/dirvish/jane/jane-home/2005-0305-0300/tree/fgump/src/foo des=jane:/home/fgump/src/2005-0305-0300 rsync -vvrltHpgoDx --backup-dir --numeric-ids $src $dst ---------------------------------------------------------------------- /usr/local/sbin/recover.sda ---------------------------------------------------------------------- #!/bin/bash # /usr/local/sbin/recover.sda # there can be more than one backup image directory BDIR1=2005-0312-0300 BDIR2=2005-0315-0300 S=/backup/dirvish/mom T=/new DISK=/dev/sda SFD=$S/sfdisk.out MKDIR='/bin/mkdir ' MKFS='/sbin/mkfs.ext3 ' MOUNT='/bin/mount ' ECHO='/bin/echo ' COPY='/usr/bin/cp -a' E='tree/' # If you have not partitioned the target disk already, # and want to use the same disk structure as before, # uncomment the line below: #/bin/cat $SFD | sfdisk --force $DISK # set up partitions, THIS IS VERY DISK DEPENDENT $MKFS ${DISK}1 $MKFS ${DISK}5 $MKFS ${DISK}6 $MKFS ${DISK}7 # make the swap partition /sbin/mkswap ${DISK}8 #mount point for new disk $MKDIR $T # mount and fill partitions, THIS IS VERY DISK DEPENDENT $ECHO "now copying root" $MOUNT ${DISK}5 $T $COPY $S/mom-root/$BDIR1/$E $T $ECHO "now copying boot" $MOUNT ${DISK}1 $T/boot $COPY $S/mom-boot/$BDIR1/$E $T/boot $ECHO "now copying usr" $MOUNT ${DISK}6 $T/usr $COPY $S/mom-usr/$BDIR1/$E $T/usr $ECHO "now copying home" $MOUNT ${DISK}7 $T/home $COPY $S/mom-home/$BDIR2/$E $T/home # make the proc mount point $MKDIR $T/proc # install the grub boot loader /sbin/grub --batch --device-map=/dev/null << EOF device (hd1) ${DISK} root (hd1,0) setup (hd1) quit EOF exit 0 ---------------------------------------------------------------------- Removing client-sensitive data for xyzcorp: ----------------------------------------------------------------- #!/bin/bash hdparm -zb 1 /dev/backup mount /dev/backup /backup # files removed here rm -rf /backup/dirvish/jane/jane-home/200*/tree/fgump/xyzcorp rm -rf /backup/dirvish/jane/jane-home/200*/tree/fgump/Maildir/xyzmail rm -rf /backup/dirvish/dick/dick-home/200*/tree/cnerd/data/xyzcorp # ... more files and directories ... # umount /dev/backup hdparm -b 0 /dev/backup -----------------------------------------------------------------