Backups completely filling root drive.

Larry Alkoff labradley at
Wed Sep 27 14:09:30 UTC 2006

Tony Arnold wrote:
> Larry,
> On Tue, 2006-09-26 at 18:04 -0500, Larry Alkoff wrote:
>> First I want to thank you Tony for helping find out just what was going on.
> No problem. It's what this list is all about.
>> Before Kubuntu I used Slackware for many years and developed a script 
>> called mirror which ran every night.  Mirror would update an identical 
>> hard disk that was originally prepared with dd.  The update would be by 
>> rsync on two passes.  It ends up kind of like a raid 1 with the added 
>> advantage that I have until 4am each day to undo anything I did wrong 
>> instead of having mistakes written to both drives immediately.
> That's a really neat idea.
>> The first pass would rsync (for selected dirs in list) --exclude /home 
>> to mnt/kinda1/ and the second would rsync /home to /mnt/kinda1/home.
>> I'm going to update this script for Kubuntu which will separate out 
>> /home from the / update but still allow me to mount the target disk as 
>> /mnt/kinda1 and /mnt/kinda1/home.
> Probably won't need much updating, with a bit of luck.
>> What do you think of this idea?  Would you comment on the script when I 
>> get it done?
> A great idea. I'd be happy to comment on the script, but I suggest you
> post it to the list so others can comment too if they want.
> Regards,
> Tony.

This is the rsync script.  There is a little wrapping in places since my 
mailer limits the line length.

root at kinda bin # cat mirrorkub
# lba: mirrorkub - use rsync to update a hard disk

# Variables:
# TEE=2>&1 |tee >>/var/log/mirror.log
TEE='tee >>/var/log/mirror.log'

# First prepare a similiar mirror hard disk using dd - for example:
# dd if=/dev/hda of=/dev/hdb bs=16M

# make sure we're running as root
if [ `/usr/bin/id -u` != 0 ]; then { /bin/echo "Sorry only root can do 
this.  Exiting..."; exit 1; } fi

# Only -n parameter allowed
if [ ! $1 = "-n" ]; then
         echo Bad parameter.  Aborting!
         exit 1

if [ ! -d $MIRROR ]; then mkdir $MIRROR; fi
if [ ! -d $MIRROR/home ]; then mkdir $MIRROR/home; fi
# if [ ! -d $MIRROR/extra ]; then mkdir $MIRROR/extra; fi

echo Mounting all the mirror disk partitions:
mount -v $MIRROR                2>/dev/null
mount -v $MIRROR/home           2>/dev/null
# mount -v $MIRROR/extra                2>/dev/null

## exit         # enable to mount only

# Delete the last log:
# rm /var/log/mirror.log

# Display banner:
#echo "Mirror: started2 `/usr/bin/date`" >>/var/log/mirror.log

echo "" >>/var/log/mirror.log
echo "" >>/var/log/mirror.log
echo -n "       Mirror: " >>/var/log/mirror.log
echo -n "started " >>/var/log/mirror.log
date +"%A    %B %e, %Y    %l:%M %P    doy=%j" >>/var/log/mirror.log
echo "" >>/var/log/mirror.log
echo "" >>/var/log/mirror.log

# Loop to update the selected directories:
#       Note: The trailing / for SOURCE ( eg: /bin/ ) is _crucial_!
# ----------------------------------------
## for SOURCE in  /bin/ /boot/ /dev/ /etc/ /home/ /lib/ /opt/ /root/ 
/sbin/ /usr/ /var/ /extra/ ; do
## 6/25/05 Eliminated /extra bec it takes 4 hours! rsync line problem?

# These are _all_ the root directories of Kubuntu:
         ###  Which ones to include ??  What does /srv/ do?
# /bin/ /boot/ /dev/ /etc/ /home/ /initrd/ /lib/ /lost+found/ /media/ \
# /mnt/ /opt/ /proc/ /root/ /sbin/ /srv/ /sys/ /tmp/ /usr/ /var/

# For ubuntu:
for SOURCE in /bin/ /boot/ /dev/ /etc/ /home/ /initrd/ /lib/ \
         /opt/ /root/ /sbin/ /srv/ /usr/ /var/ ; do
       # Does not include /lost+found/ /media/ /mnt/ /proc/ /sys/  /tmp/

     echo "Working in $SOURCE ................................... $SOURCE"
     echo >>/var/log/mirror.log
     echo -n "`date` " >>/var/log/mirror.log
     echo -n "Working in $SOURCE: " >>/var/log/mirror.log

   if [ $SOURCE = "/home/" ]; then
#     EXCLUDE="--exclude lba/.opera/cache4/"
      EXCLUDE="--exclude lba/.opera/cache4/  --exclude lba/Muttmail/ 
--exclude lba/dl/"
      # note: --exclude is relative to the source path.  Above works!

# add cH to options

    echo "command: rsync -uacHv $1 --delete $TESTING $EXCLUDE $SOURCE 
$MIRROR$SOURCE" >>/var/log/mirror.log
    rsync -uacHv $1 --delete $EXCLUDE $SOURCE $MIRROR$SOURCE 
      # eliminated --progress (too much verbiage), --stats

echo  Unmounting all the mirror disk partitions:
# umount -v $MIRROR/extra       2>/dev/null
umount -v $MIRROR/home          2>/dev/null
umount -v $MIRROR/              2>/dev/null

echo  Removing all the mirror disk partitions:
# rmdir -p $MIRROR/extra
rmdir -p $MIRROR/home
rmdir    $MIRROR

if [ isdir = 0 ]; then
         echo Something went wrong - partitions did not unmount 
         echo Partitions ummounted sucessfully >>/var/log/mirror.log

echo "" >>/var/log/mirror.log
echo "Mirror: completed " `date` >>/var/log/mirror.log
echo "    Log is in /var/log/mirror.log"
echo "" >>/var/log/mirror.log

exit 0

# Information on rsync options:
# -----------------------------
# I am using rsync -uacHv

# List of options:
#  -a = -rlptgoD
#       -r = recurse
#       -l = copy symlinks as symlinks
#       -p = preserve permissions
#       -t = perserve times
#       -g = preserve group
#       -o = preserve owner   (root only)
#       -D = preserve devices (root only)
# -u = update
# -c = compare checksum of source and target
# -H = preserve hard links
# --stats = display statistics
# --exclude = exclude PATTERN (relative to source path)
# -b --backup = backup changed files with default ~
# --suffix = backup suffix other than ~
# --log-format = format like man rsyncd.conf
# --progress = display progress
# --delete = delete files on $MIRROR that do not exist on source
#            Can be dangereous - do dry-run first!
# --force = force deletion of directories even if not empty

Larry Alkoff N2LA - Austin TX
Using Thunderbird on Linux

More information about the ubuntu-users mailing list