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.
14 PIDFILE="/var/run/backup-script.pid"
20 declare -i snapshots=0
22 # Default settings, can be overwritten in backup-script.conf:
23 [ -d "/usr/local/etc/backup-script.d" ] \
24 && conf_d="/usr/local/etc/backup-script.d" \
25 || conf_d="/etc/backup-script.d"
29 # Search configuration file (last one is used as default!)
31 "/usr/local/etc/backup-script.conf" \
32 "/etc/backup-script.conf" \
33 "${conf_d}/backup-script.conf" \
34 "/usr/local/etc/backup-script.conf" \
36 if [ -r "$conf" ]; then
46 if [ "$QUICK" = "0" ]; then
47 size=`du -Hhs "$1" | cut -f1`
48 echo "$2 - Size:" $size
57 if [ "$(uname)" = "Linux" ]; then
58 last=`LC_ALL=C stat "$1" | grep "^Modify: " \
59 | cut -d':' -f2- | cut -d. -f1`
61 last=`LC_ALL=C stat -f "%Sc" "$1"`
63 [ -n "$last" ] && echo "$2 - Date:" $last
68 24) txt=", WARNING (some files vanished during backup)"; ;;
71 [ -n "$code" ] && echo "$2 - Result code: $code$txt"
73 echo "$2 - No timestamp recorded! Backup currently running or aborted?"
77 if [ "$1" == "-r" -o "$1" == "--running" ]; then
78 pid="$(cat "$PIDFILE" 2>/dev/null)"
79 if [ -n "$pid" ]; then
80 if kill -0 "$pid" >/dev/null 2>&1; then
81 echo "Backup job running with PID $pid."
84 echo "No backup running (invalid PID $pid in \"$PIDFILE\")."
88 echo "No backup running (no PID file \"$PIDFILE\" found)."
92 if [ "$1" == "-q" ]; then
99 echo "Usage: $NAME [-q] [<system> [<system> [...]]]"
100 echo " $NAME {-r|--running}"
105 if [ $# -ge 1 ]; then
107 if [ ! -r "${conf_d}/$s" ]; then
108 echo "$NAME: Can' read \"${conf_d}/$s\"!"
111 sys="$sys ${conf_d}/$s"
117 [ -r "${conf_d}/backup-script.conf" ] && source "${conf_d}/backup-script.conf"
120 [ -r "$f" -a -f "$f" ] || continue
124 "backup-script.conf"|*.sh)
129 # Set global defaults
131 target="$default_target"
132 generations="$default_generations"
134 # Read in system configuration file
137 target="$target/$system"
139 [ -d "$target" ] || continue
142 [ "$system" = "$fname" ] && echo "$fname" || echo "$fname [$system]"
144 # System target directory
145 echo "- Target: $target"
147 if [ $generations -gt 0 ]; then
148 for s in $target/current $target/[0-9]*-[0-9]*; do
149 [ -e "$s" ] || continue
150 echo " - Snapshot: $s"
152 Check_Stamp "$s/.stamp" " "
153 snapshots=$snapshots+1
156 # Timestamp and result code
158 Check_Stamp "$target/.stamp"
159 snapshots=$snapshots+1
166 if [ $count -lt 1 ]; then
167 echo "No backups found!"
170 [ $count -eq 1 ] && sc="" || sc="s"
171 [ $snapshots -eq 1 ] && ss="" || ss="s"
172 echo "$count system backup$sc found, $snapshots snapshot$ss."