archive rotation

Upload: spallihari

Post on 03-Jun-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/12/2019 Archive Rotation

    1/3

    2/28/2014 Archive Rotation

    https://help.ubuntu.com/12.04/serverguide/backups-shellscripts-rotation.html 1/3

    Archive RotationThe shell script in Shell Scripts only allows for seven different archives. For a server whose data doesn't changeoften, this may be enough. If the server has a large amount of data, a more complex rotation scheme should be used.

    Rotating NFS Archives

    Tape Drives

    Rotating NFS ArchivesIn this section, the shell script will be slightly modified to implement a grandfather-father-son rotation scheme(monthly-weekly-daily):

    1. The rotation will do a daily backup Sunday through Friday.

    2. On Saturday a weekly backup is done giving you four weekly backups a month.

    3. The monthly backup is done on the first of the month rotating two monthly backups based on if the month is oddor even.

    Here is the new script:

    #!/bin/bash###################################### Backup to NFS mount script with# grandfather-father-son rotation.#####################################

    # What to backup.backup_files="/home /var/spool/mail /etc /root /boot /opt"

    # Where to backup to.dest="/mnt/backup"

    # S etup va riables for the archive filename.day=$(date +%A)hos tname=$(host name -s)

    # Find which week o f the month 1-4 it is.

    day_num=$(date +%d)if (( $day_num 7 && $day_num 14 && $day_num 21 && $day_num < 32 )); then week_file="$hostname-week4.tgz"fi

    # Find if the Month is odd or even.

    https://help.ubuntu.com/12.04/serverguide/backups-shellscripts-rotation.html#backup-shellscript-tapedrivehttps://help.ubuntu.com/12.04/serverguide/backups-shellscripts-rotation.html#backups-nfs-rotationhttps://help.ubuntu.com/12.04/serverguide/backup-shellscripts.htmlhttps://help.ubuntu.com/12.04/serverguide/backup-shellscripts.htmlhttps://help.ubuntu.com/12.04/serverguide/backups-shellscripts-rotation.html#backup-shellscript-tapedrivehttps://help.ubuntu.com/12.04/serverguide/backups-shellscripts-rotation.html#backups-nfs-rotation
  • 8/12/2019 Archive Rotation

    2/3

    2/28/2014 Archive Rotation

    https://help.ubuntu.com/12.04/serverguide/backups-shellscripts-rotation.html 2/3

    month_num=$(date +%m)month=$(expr $month_num % 2)if [ $month -eq 0 ]; then month_file="$hostname-month2.tgz"else month_file="$hostname-month1.tgz"fi

    # Create archive filename.

    if [ $day_num == 1 ]; then archive_file=$month_fileelif [ $day != "Saturday" ]; then archive_file="$hostname-$day.tgz"else

    archive_file=$week_filefi

    # Print start status message.echo "Backing up $backup_files to $dest/$archive_file"dateecho

    # Backup the files using tar.tar czf $dest/$archive_file $backup_files

    # Print end status message.echoecho "Backup finished"date

    # Long listing of files in $dest to check file sizes.ls -lh $dest/

    The script can be executed using the same methods as in Executing the Script .

    It is good practice to take backup media off-site in case of a disaster. In the shell script example the backup media isanother server providing an NFS share. In all likelihood taking the NFS server to another location would not bepractical. Depending upon connection speeds it may be an option to copy the archive file over a WAN link to a serverin another location.

    Another option is to copy the archive file to an external hard drive which can then be taken off-site. Since the price of external hard drives continue to decrease, it may be cost-effective to use two drives for each archive level. This wouldallow you to have one external drive attached to the backup server and one in another location.

    Tape Drives A tape drive attached to the server can be used instead of an NFS share. Using a tape drive simplifies archiverotation, and makes taking the media off-site easier as well.

    When using a tape drive, the filename portions of the script aren't needed because the data is sent directly to the tapedevice. Some commands to manipulate the tape are needed. This is accomplished using mt , a magnetic tape controlutility part of the cpio package.

    Here is the shell script modified to use a tape drive:

    https://help.ubuntu.com/12.04/serverguide/backup-shellscripts.html#backup-executing-shellscript
  • 8/12/2019 Archive Rotation

    3/3

    2/28/2014 Archive Rotation

    https://help.ubuntu.com/12.04/serverguide/backups-shellscripts-rotation.html 3/3

    #!/bin/bash###################################### Backup to tape drive script.#####################################

    # What to backup.backup_files="/home /var/spool/mail /etc /root /boot /opt"

    # Where to backup to.dest="/dev/st0"

    # Print start status message.echo "Backing up $backup_files to $dest"dateecho

    # Make sure the tape is rewound.mt -f $dest rewind

    # Backup the files using tar.tar czf $dest $backup_files

    # Rewind and eject the tape.mt -f $dest rewoffl

    # Print end status message.echoecho "Backup finished"date

    The default device name for a SCSI tape drive is /dev/st0 . Use the appropriate device path for your system.

    Restoring from a tape drive is basically the same as restoring from a file. Simply rewind the tape and use the devicepath instead of a file path. For example to restore the /etc/hosts file to /tmp/etc/hosts :

    mt -f /dev/st0 rewindtar -xzf /dev/st0 -C /tmp etc/hosts