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"
21 declare -i snapshots=0
23 # Default settings, can be overwritten in backup-script.conf:
24 [ -d "/usr/local/etc/backup-script.d" ] \
25 && conf_d="/usr/local/etc/backup-script.d" \
26 || conf_d="/etc/backup-script.d"
27 default_target="/var/backups"
30 # Search configuration file (last one is used as default!)
32 "/usr/local/etc/backup-script.conf" \
33 "/etc/backup-script.conf" \
34 "${conf_d}/backup-script.conf" \
35 "/usr/local/etc/backup-script.conf" \
37 if [ -r "$conf" ]; then
44 echo "Usage: $NAME [-q|--quick] [<system> [<system> [...]]]"
45 echo " $NAME {-r|--running}"
53 if [ "$QUICK" = "0" ]; then
54 size=`du -Hhs "$1" | cut -f1`
55 echo "$2 - Size:" $size
64 if [ "$(uname)" = "Linux" ]; then
65 last=`LC_ALL=C stat "$1" | grep "^Modify: " \
66 | cut -d':' -f2- | cut -d. -f1`
68 last=`LC_ALL=C stat -f "%Sc" "$1"`
70 [ -n "$last" ] && echo "$2 - Date:" $last
75 24) txt=", WARNING (some files vanished during backup)"; ;;
78 [ -n "$code" ] && echo "$2 - Result code: $code$txt"
80 echo "$2 - No timestamp recorded! Backup currently running or aborted?"
85 echo " - Snapshot: $1"
87 Check_Stamp "$1/.stamp" " "
90 if [ "$1" == "-r" -o "$1" == "--running" ]; then
91 pid="$(cat "$PIDFILE" 2>/dev/null)"
92 if [ -n "$pid" ]; then
93 if kill -0 "$pid" >/dev/null 2>&1; then
94 echo "Backup job running with PID $pid."
96 pstree -ap "$pid" 2>/dev/null
99 echo "No backup running (invalid PID $pid in \"$PIDFILE\")."
103 echo "No backup running (no PID file \"$PIDFILE\" found)."
107 while [ $# -gt 0 ]; do
124 if [ $# -ge 1 ]; then
126 if [ ! -r "${conf_d}/$s" ]; then
127 echo "$NAME: Can' read \"${conf_d}/$s\"!"
130 sys="$sys ${conf_d}/$s"
137 [ -r "$f" -a -f "$f" ] || continue
141 "backup-script.conf"|*.sh)
146 # Set global defaults
148 target="$default_target"
149 generations="$default_generations"
151 # Read in system configuration file
154 target="$target/$(basename "$f")"
156 [ -d "$target" ] || continue
159 [ "$system" = "$fname" ] && echo "$fname" || echo "$fname [$system]"
161 # System target directory
162 echo "- Target: $target"
164 if [ $generations -gt 0 ]; then
165 if [ "$ONLY_LATEST" = "0" ]; then
166 for s in $target/[0-9]*-[0-9]* $target/current; do
167 [ -e "$s" ] || continue
169 snapshots=$snapshots+1
171 elif [ -e "$target/latest" ]; then
172 Snapshot_Info "$target/latest"
173 snapshots=$snapshots+1
176 # Timestamp and result code
178 Check_Stamp "$target/.stamp"
179 snapshots=$snapshots+1
186 if [ $count -lt 1 ]; then
187 echo "No backups found!"
190 [ $count -eq 1 ] && sc="" || sc="s"
191 [ $snapshots -eq 1 ] && ss="" || ss="s"
192 echo "$count system backup$sc found, $snapshots snapshot$ss."