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 conf_d="/etc/backup-script.d"
26 for conf in "/etc/backup-script.conf" "${conf_d}/backup-script.conf"; do
27 if [ -r "$conf" ]; then
36 if [ "$QUICK" = "0" ]; then
37 size=`du -Hhs "$1" | cut -f1`
38 echo "$2 - Size:" $size
47 if [ `uname` = "Linux" ]; then
48 last=`LC_ALL=C stat "$1" | grep "^Modify: " \
49 | cut -d':' -f2- | cut -d. -f1`
51 last=`LC_ALL=C stat -f "%Sc" "$1"`
53 [ -n "$last" ] && echo "$2 - Date:" $last
58 24) txt=", WARNING (some files vanished during backup)"; ;;
61 [ -n "$code" ] && echo "$2 - Result code: $code$txt"
63 echo "$2 - No timestamp recorded! Backup currently running or aborted?"
67 if [ "$1" == "-q" ]; then
74 echo "Usage: $NAME [-q] [<system> [<system> [...]]]"
81 if [ ! -r "${conf_d}/$s" ]; then
82 echo "$NAME: Can' read \"${conf_d}/$s\"!"
85 sys="$sys ${conf_d}/$s"
91 [ -r "${conf_d}/backup-script.conf" ] && source "${conf_d}/backup-script.conf"
94 [ -r "$f" -a -f "$f" ] || continue
98 "backup-script.conf"|*.sh)
103 # Set global defaults
105 target="$default_target"
106 generations="$default_generations"
108 # Read in system configuration file
111 # Validate configuration
112 [ "$system" = "localhost" -o "$system" = "127.0.0.1" ] && local=1
115 target="$target/$system"
117 [ -d "$target" ] || continue
120 [ "$system" = "$fname" ] && echo "$fname" || echo "$fname [$system]"
122 # System target directory
123 echo "- Target: $target"
125 if [ $generations -gt 0 ]; then
126 for s in $target/current $target/[0-9]*-[0-9]*; do
127 [ -e "$s" ] || continue
128 echo " - Snapshot: $s"
130 Check_Stamp "$s/.stamp" " "
131 snapshots=$snapshots+1
134 # Timestamp and result code
136 Check_Stamp "$target/.stamp"
137 snapshots=$snapshots+1
144 if [ $count -lt 1 ]; then
145 echo "No backups found!"
148 [ $count -eq 1 ] && sc="" || sc="s"
149 [ $snapshots -eq 1 ] && ss="" || ss="s"
150 echo "$count system backup$sc found, $snapshots snapshot$ss."