I'm still using this backup script to back up ~/cron/ as its got my reinstall.sh script in which I need for installing, so it seems sensible to keep access to it.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/sh -e
#: Title            : backup
#: Date             : July 2013
#: Author           : Keith Edwards (GLLUG), Moggers87, and Sharon Kimble.
#: Version          : 5.6
#: Description      : Backs up and retains a certain number of days worth before deleting them in a cycle. Works with rsync from the users crontab.
#: Options          : Nine options, all shown under '# Variables'.
#: License          : GNU GPL 3.0 or later
####################################################
# CHANGELOG.
# v5.5 [30-6-2013]
# Added in LOG_FILE.
# Released under GNU GPL 3.
# v5.6 [8-7-2013]
# Changed 'USB_DIR' to reflect the change in saving of files on Debian and Thunar
# removed '--exclude-from '/home/boudiccas/cron/xclude.txt' \' as no longer needed. 
####################################################
# Variables
HOME_DIR="/home/boudiccas/cron"
USB_DIR="/media/boudiccas/backup/back/cron"
BACKUP_DIR="$USB_DIR/$(/bin/date +%Y%m%d)"
EMAIL="[email protected]"
SUBJECT="Backup Error"
EMAIL_MESSAGE="Couldn't find $USB_DIR, are you sure its plugged in or mounted?"
NUM_LEFT="14" #number of days backups to hold
LOG_FILE="/home/boudiccas/cron/backup.txt"
####################################################
# Don't change anything after here.

# Check if rsync still running
if pgrep -f 'rsync.*/home/'; then echo "E: old rsync still running" 1>&2; exit 1; fi

# Backup files
if [ -d $HOME_DIR ] & [ -d $USB_DIR ]; then
        [ -d $BACKUP_DIR ] || mkdir $BACKUP_DIR \
                >> $LOG_FILE 2>&1
        /usr/bin/rsync  -avzP /home/boudiccas/cron $BACKUP_DIR \
                >>$LOG_FILE 2>&1

        # Delete those old backups! Yeah!
        (find $USB_DIR -maxdepth 1 -type d -name "20*" | sort | tail -n $NUM_LEFT; \
                find $USB_DIR -maxdepth 1 -type d -name "20*") | \
                sort | uniq -u | xargs -n1 rm -rf \
                >>$LOG_FILE 2>&1
else
        # Send an email
    /bin/mail -s "$SUBJECT" "$EMAIL" < "$EMAIL_MESSAGE"

    #kill all unwanted rsync programmes
         /usr/bin/killall rsync

fi


Comments

comments powered by Disqus