#!/bin/bash # # bakup - Backup most personal files to CD image (run as root) # # --excludes are TRICKY. For tar, use single quotes around complete # exact matches you want excluded (ie. "/home/giles/.netscape/cache/*"). ########## Variables ###################################### cdBase="/tmp" # Where to write the image reqSpace=1400000 # Required space on $cdBase, in kb dateStamp="$(date +%Y%m%d.%H%M)" # Let this user and group own the image (which will be 600) cdOwner="giles" ; cdGroup="giles" bakDir="${cdBase}/bakup.${dateStamp}" log=${bakDir}/$(basename $0).${dateStamp}.log # Don't put $cdImageName in $bakDir, or it will try to include # itself in the CD image ... cdImageName="${cdBase}/cd_backup.${dateStamp}.iso" # Name of the CD image testMount="/mnt/tmp" ######### End Variables #################################### su - ${cdOwner} -c "rm ${eraseOld}" # Check if there's enough space in $cdBase freeSpace="$(df ${cdBase} | grep -v Filesystem | awk '{print $4}')" if [ "${freeSpace}" -le "${reqSpace}" ] then # We don't have enough space echo "Less than ${reqSpace} kb on ${cdBase}. Exiting." exit 1 fi # Check $bakDir is writeable if ! mkdir ${bakDir} then echo "Unable to create ${bakDir} - aborting backup." exit 2 fi chown ${cdOwner}.${cdGroup} ${bakDir} touch ${log} # List all rpms on the system: rpm -qa > ${bakDir}/rpmlist.${dateStamp}.txt # Back up the files you want: tar -cvz \ -f ${bakDir}/etc.${dateStamp}.tar.gz \ /etc/ \ | tee -a ${log} tar -cvz \ --exclude '/home/giles/download/*' \ --exclude '/home/nikola/*' \ --exclude '/home/giles/.netscape/cache/*' \ --exclude '/home/giles/.kde/share/apps/kio_http/cache/*' \ --exclude '/home/giles/tmp/*' \ --exclude '/home/giles/News/*' \ -f ${bakDir}/home.${dateStamp}.tar.gz \ /home/ \ /mm/music/Notes/ \ | tee -a ${log} tar -cvz \ --exclude '/root/download/*' \ --exclude '/root/.netscape/cache/*' \ --exclude '/root/tmp/*' \ --exclude '/root/bakup/*' \ -f ${bakDir}/root.${dateStamp}.tar.gz \ /root/ \ | tee -a ${log} # For /my-usr/ which is nothing but links, override the normal # behaviour of not following links: tar -cvz \ --dereference \ -f ${bakDir}/my-usr.${dateStamp}.tar.gz \ /my-usr/ \ | tee -a ${log} # /var/ is important: mail is there! tar -cvz \ -f /root/bakup/var.${dateStamp}.tar.gz \ /var/ \ | tee -a ${log} mkisofs -r -v -J -o ${cdImageName} ${bakDir} # Below is not a secure measure, but it works and this is home ... chown --recursive ${cdOwner}.${cdGroup} ${bakDir} ${cdImageName} cdSize="$(ls --size --human-readable ${cdImageName} | awk '{print $1}')" mount -t iso9660 -o ro,loop=/dev/loop1 ${cdImageName} ${testMount} echo "${cdImageName} (size ${cdSize}) is mounted at ${testMount}. Please examine the image. Write it with a command like the following: cdrecord -v speed=2 blank=fast dev=1,0,0 -data ${cdImageName} Finally, clean up: rm -r ${bakDir} ${cdImageName} (as ${cdOwner}) rm ${cdImageName} "