Sending out a couple of scripts for backing up entire disks and files for Linux. We are currently backing up to a ZFS Appliance share since we don’t have enough ports for a backup network. Each of these scripts will do a count of existing backup files and remove anything older.
dd_backup.sh
#/bin/bash source="sda" dest="/zfssa/os_backup" backup="`uname -n |awk -F. '{print $1}'`_bootdisk_backup.latest" archive="`uname -n |awk -F. '{print $1}'`_bootdisk_backup" if [ -f $dest/$backup ];then cd $dest ls -t $dest/$backup*-* | tail -n +1 | xargs -d '\n' rm mv $dest/$backup $dest/"$archive""_"`date +%m%d%y%M%H` dd if=/dev/$source of=$dest/$backup conv=sync,noerror & else dd if=/dev/$source of=$dest/$backup conv=sync,noerror & fi
file_backup.sh
#!/bin/bash #################################### # # Backup to NFS mount script. # #################################### hostname=$(hostname -s) backup_files="/u01 /opt /home/oracle /home/grid /etc" dest="/zfssa/os_backup/file_backup" count=$(ls $dest/$backup/$hostname* |wc -l) if [[ "$count" -gt 2 ]]; then ls -t $dest/$hostname* | tail -n +3 | xargs -d '\n' rm # Create archive filename. day=$(date +%A) hostname=$(hostname -s) archive_file="$hostname-$day.tgz" 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 else # Create archive filename. day=$(date +%A) hostname=$(hostname -s) archive_file="$hostname-$day.tgz" 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 fi