#!/bin/bash #DESC Create 7 partitions on a passport for a backup each day of the week. # This script will configure rtibackup.pl to run seperate, full backups for each day of the week on the same backup device. # Note: This script trusts your device is big enough for 7, seperate, 600GB partitions on your backup device, and that is large enough for your backup. # Note2: There will be seven partions on the backup device. The number of the partition corrisponds to the day of the week + 4. Example: Mon = /dev/sdX5; Tues = /dev/sdX6; etc. # Sample cron job # 05 03 * * * root (/usr/bin/test -e /usr2/bbx && . /etc/profile.d/rti.sh && /usr2/bbx/bin/rtibackup.pl --rti --configfile=/usr2/bbx/config/backups.config --device=/dev/sdb$(expr $(date +"\%u") + 4) --backup=all --verify --console) # Find device # check conf file first BACKUPDEVICE=`grep -i ^device=/dev/sd /usr2/bbx/config/backups.config` # assign default if none in conf file [ "$BACKUPDEVICE" == "" ] && BACKUPDEVICE=/dev/sdb # verify exists in /dev BACKUPDEVICE=`ls $BACKUPDEVICE 2>/dev/null` [ "$BACKUPDEVICE" == "" ] && echo "No backup device found." && exit 1 # check for incremental installed already and ask for format only if so. #[ "`grep -i ^device=$BACKUPDEVICE\$((\`date +\"%u\"\` + 4))" /usr2/bbx/config/backups.config`" != "" ] && echo "Backup device already configured for incremental. Continue formatting $BACKUPDEVICE?" && read -n RESP [ "$RESP" == "n" ] && exit 0 # Partition and format device # wipe exisiting partition table echo -n "About to format $BACKUPDEVICE. Proceed? (y/n): " read CONT [ "$CONT" == "n" ] && exit 0 echo "Wiping partition table on $BACKUPDEVICE ..." wipefs -a $BACKUPDEVICE echo "Configuring $BACKUPDEVICE..." # writing gpt label (for large disks) sed -e 's/\s*\([\+0-9a-zA-Z]*\).*/\1/' << EOF | fdisk $BACKUPDEVICE g w EOF # create fist extended primary partition #sed -e 's/\s*\([\+0-9a-zA-Z]*\).*/\1/' << EOF | fdisk $BACKUPDEVICE # n # e # 4 # # # w #EOF # partitions for part in 5 6 7 8 9 10 11 do sed -e 's/\s*\([\+0-9a-zA-Z]*\).*/\1/' << EOF | fdisk $BACKUPDEVICE n $part +600G w EOF done # reread partition table partprobe $BACKUPDEVICE sleep 4 # format for part in 5 6 7 8 9 10 11 do mkfs.ext2 -F -F $BACKUPDEVICE$part done echo "$BACKUPDEVICE configured." echo "Done." exit 0