3 # Copyright (c) 2007-2008 Thomas Pani <thomas.pani/at/gmail.com>
5 # Permission is hereby granted, free of charge, to any person obtaining a copy
6 # of this software and associated documentation files (the "Software"), to deal
7 # in the Software without restriction, including without limitation the rights
8 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 # copies of the Software, and to permit persons to whom the Software is
10 # furnished to do so, subject to the following conditions:
12 # The above copyright notice and this permission notice shall be included in
13 # all copies or substantial portions of the Software.
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 ### EDIT THESE THREE LINES TO MATCH YOUR SETUP!!! ###
27 # (hostname and source will be added automatically)
28 DST
="/media/PANIHDD/backup"
29 # file containing a list of files/dirs to exclude
30 # (see `man rsync' on --exclude-from for more info)
31 EXCLUDES
="/home/thomas/.backup_excludes"
32 ##### DO NOT EDIT ANYTHING BELOW HERE #####
33 ### (unless you know what you're doing) ###
36 echo "Backup script v${VERSION}."
39 date=$
(date "+%Y-%m-%d__%H-%M-%S")
40 BAK_DST
="${DST}/${HOSTNAME}/${SRC//\//_}"
42 # make sure we're running as root
43 if [ $
(id
-u) != 0 ] ; then
44 echo "Sorry, must be root. Exiting..."
48 # make sure backup destination is mounted
49 if [ ! -d $DST ] ; then
50 echo "Please mount backup media. Exiting..."
55 if [ ! -d $BAK_DST ] ; then
60 echo "Here's a list of changes:"
62 RSYNC_OUTPUT
=$
(rsync
-n -a -i -x -P --delete --delete-excluded --exclude-from="$EXCLUDES" --link-dest=${BAK_DST}/current/ ${SRC}/ ${BAK_DST}/backup-${date} |
grep -v ^
cd)
63 if [ $
(echo "$RSYNC_OUTPUT" |
wc -l ${TMPFILE} | cut
-d ' ' -f1) -gt 22 ] ; then
64 echo "$RSYNC_OUTPUT" |
less
70 echo -n "Would you like to sync these changes? [y/n] "
75 'n' ) echo "Exiting..." ; exit ;;
76 * ) echo "Invalid answer. Exiting..." ; exit 1 ;;
80 rsync
-a -i -x -P --delete --delete-excluded --exclude-from="$EXCLUDES" --link-dest=${BAK_DST}/current/ ${SRC}/ ${BAK_DST}/backup-${date} |
grep -v ^
cd
81 if [ $?
-ne 0 ] ; then
82 echo "Error during rsync. Exiting..."
86 # safe link to current backup
87 if [ -L ${BAK_DST}/current
] ; then
90 ln -s backup-
${date} ${BAK_DST}/current
94 echo "Finished backup to ${BAK_DST}"