Lab #18: Backups
Date: April 21, 2008

Backing up with Tar

  1. Create a backup of the /home partition.
    mkdir /var/backups
    cd !$
    tar cjf home_backup_`date +%F`.tar.bz2 /home
    
  2. View the contents of the backup
    tar tjf home_backup_`date +%F`.tar.bz2 
    tar tvjf !$ 
    
  3. Restore the backup to /tmp.
    cd /tmp
    tar xvjf /var/backups/home_backup_`date +%F`.tar.bz2 
    ls -lR home
    
  4. Remove the restore directory once you've verified it works.
    rm -rf /tmp/home
    

Network Backups

  1. Start your virtual machine. I'll refer to the IP address of the CentOS VM as IPADDR.

  2. Copy your backup from the previous section to the VM.
    scp -p /var/backups/home_backup_`date +%F`.tar.bz2 IPADDR:/var
    
  3. Performing backups as a two step process using tar first, then copying the resulting file across the network, uses a lot of disk space on the machine being backed up. Many machines may not have the disk space for this network backup mechanism to work. Therefore, we need to perform the backup as a single step, without using a temporary file on the local disk.
    tar cvjf - /home | ssh IPADDR "cat >/var/wbel-home.tar.bz2"
    
    If we had a tape drive on the remote machine, we could use this command to write directly to tape:
    tar cjvf - /home | ssh tape_server "cat >/dev/tape"
    
  4. Restore the backup on the VM. Sometimes, especially when you're not restoring a current working disk on a server, you may want to restore files to the backup server.
    cd /tmp
    tar xvjf /var/wbel-home.tar.bz2
    ls -lR home
    
  5. Restore the backup stored on the backup server (VM) to the WBEL machine. Restoring the backup on the original host it came from is a common technique to recover from a failed disk or similar hardware mishap.
    cd /tmp
    ssh IPADDR "cat /var/wbel-home.tar.bz2" | tar xjvf -
    ls -lR home
    
    Include your command history and the results of your two restores in your lab.txt file.

LVM Snapshots

  1. Remove logical volume created in an earlier lab if it still exists.
    umount /iso
    lvremove /dev/cit470/my_isos
    vgdisplay -v
    
  2. Create new logical volume, leaving room in VG for snapshots
    lvcreate -n users --size 4G cit470          # Create a 4GB users volume
    mke2fs -v -j /dev/cit470/users              # Make an ext3 filesystem
    mkdir /users                                # Create a mount point
    vim /etc/fstab                              # Cfg /users to mount on boot
    mount /users                                # Mount /users
    
  3. Create test files under /users.
    cd /users
    tar xvjf /var/backup/home_*
    mv home/student .
    rm -rf home
    dd if=/dev/zero of=/users/2MB_File bs=2048 count=1024
    
  4. Load the Snapshot kernel module
    modprobe dm-snapshot
    
  5. Create a snapshot of the users volume.
    lvcreate -s -L 100M -n users_snap /dev/cit470/users
    
  6. Check the logical volume status information.
    lvs
    
  7. Mount the snapshot and examine its contents. How do they compare to the contents of the original volume?
    mkdir /users/snap
    mount /dev/cit470/users_snap /users/snap
    ls -l /users/snap
    
  8. Remove a file from /users, simulating an accidental deletion.
    rm /users/2MB_File
    ls -l /users/2MB* /users/snap/2MB*
    
  9. Check disk usage of both logical volumes.
    lvs
    
  10. Recover the file from the snapshot.
    cp -p /users/snap/2MB_File /users
    
  11. Remove the snapshot
    umount /users/snap
    lvremove /dev/cit470/users_snap
    
  12. Implement a cron job to create a new snapshot of /users every hour. The snapshot should include a timestamp in its name. The cron job should also remove snapshots older than 24 hours. Include the crontab line and the script in your lab submission.
 

©2008 James Walden, Ph.D.