3 # backup-script system for cloning systems using rsync
4 # Copyright (c)2008-2015 Alexander Barton, alex@barton.de
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 # Please read the file COPYING, README and AUTHORS for more information.
19 declare -i snapshots=0
21 # Default settings, can be overwritten in backup-script.conf:
22 [ -d "/usr/local/etc/backup-script.d" ] \
23 && conf_d="/usr/local/etc/backup-script.d" \
24 || conf_d="/etc/backup-script.d"
28 # Search configuration file (last one is used as default!)
30 "/usr/local/etc/backup-script.conf" \
31 "/etc/backup-script.conf" \
32 "${conf_d}/backup-script.conf" \
33 "/usr/local/etc/backup-script.conf" \
35 if [ -r "$conf" ]; then
45 if [ "$QUICK" = "0" ]; then
46 size=`du -Hhs "$1" | cut -f1`
47 echo "$2 - Size:" $size
56 if [ "$(uname)" = "Linux" ]; then
57 last=`LC_ALL=C stat "$1" | grep "^Modify: " \
58 | cut -d':' -f2- | cut -d. -f1`
60 last=`LC_ALL=C stat -f "%Sc" "$1"`
62 [ -n "$last" ] && echo "$2 - Date:" $last
67 24) txt=", WARNING (some files vanished during backup)"; ;;
70 [ -n "$code" ] && echo "$2 - Result code: $code$txt"
72 echo "$2 - No timestamp recorded! Backup currently running or aborted?"
76 if [ "$1" == "-q" ]; then
83 echo "Usage: $NAME [-q] [<system> [<system> [...]]]"
90 if [ ! -r "${conf_d}/$s" ]; then
91 echo "$NAME: Can' read \"${conf_d}/$s\"!"
94 sys="$sys ${conf_d}/$s"
100 [ -r "${conf_d}/backup-script.conf" ] && source "${conf_d}/backup-script.conf"
103 [ -r "$f" -a -f "$f" ] || continue
107 "backup-script.conf"|*.sh)
112 # Set global defaults
114 target="$default_target"
115 generations="$default_generations"
117 # Read in system configuration file
120 target="$target/$system"
122 [ -d "$target" ] || continue
125 [ "$system" = "$fname" ] && echo "$fname" || echo "$fname [$system]"
127 # System target directory
128 echo "- Target: $target"
130 if [ $generations -gt 0 ]; then
131 for s in $target/current $target/[0-9]*-[0-9]*; do
132 [ -e "$s" ] || continue
133 echo " - Snapshot: $s"
135 Check_Stamp "$s/.stamp" " "
136 snapshots=$snapshots+1
139 # Timestamp and result code
141 Check_Stamp "$target/.stamp"
142 snapshots=$snapshots+1
149 if [ $count -lt 1 ]; then
150 echo "No backups found!"
153 [ $count -eq 1 ] && sc="" || sc="s"
154 [ $snapshots -eq 1 ] && ss="" || ss="s"
155 echo "$count system backup$sc found, $snapshots snapshot$ss."