Created
July 21, 2013 17:47
-
-
Save shamangeorge/6049284 to your computer and use it in GitHub Desktop.
basic archive rotation backup script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#################################### | |
# | |
# Backup to NFS mount script with | |
# grandfather-father-son rotation. | |
# | |
#################################### | |
# What to backup. | |
backup_files="/home /var/www /var/spool/mail /etc /root /boot /opt" | |
# Where to backup to. | |
dest="/media/bakup" | |
# Setup variables for the archive filename. | |
day=$(date +%A) | |
hostname=$(hostname -s) | |
# Find which week of the month 1-4 it is. | |
day_num=$(date +%d) | |
if (( $day_num <= 7 )); then | |
week_file="$hostname-week1.tgz" | |
elif (( $day_num > 7 && $day_num <= 14 )); then | |
week_file="$hostname-week2.tgz" | |
elif (( $day_num > 14 && $day_num <= 21 )); then | |
week_file="$hostname-week3.tgz" | |
elif (( $day_num > 21 && $day_num < 32 )); then | |
week_file="$hostname-week4.tgz" | |
fi | |
# Find if the Month is odd or even. | |
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_file | |
elif [ $day != "Saturday" ]; then | |
archive_file="$hostname-$day.tgz" | |
else | |
archive_file=$week_file | |
fi | |
# Print start status message. | |
echo "Backing up $backup_files to $dest/$archive_file" | |
date | |
echo | |
# Backup the files using tar. | |
tar czf $dest/$archive_file $backup_files | |
# Print end status message. | |
echo | |
echo "Backup finished" | |
date | |
# Long listing of files in $dest to check file sizes. | |
ls -lh $dest/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment