aboutsummaryrefslogtreecommitdiff
path: root/lib/backup/fs.sh
diff options
context:
space:
mode:
Diffstat (limited to 'lib/backup/fs.sh')
-rwxr-xr-xlib/backup/fs.sh92
1 files changed, 92 insertions, 0 deletions
diff --git a/lib/backup/fs.sh b/lib/backup/fs.sh
new file mode 100755
index 0000000..3950e37
--- /dev/null
+++ b/lib/backup/fs.sh
@@ -0,0 +1,92 @@
+#! /bin/bash
+
+# initdb item
+# Initializes snapshot for the given basename.
+initdb() {
+ local filename
+
+ if [ -n "$dry_run" ]; then
+ logit "initializing snapshot for $1"
+ return
+ fi
+
+ if [ $level -eq 0 ]; then
+ filename=$backup_snapshot_dir/$1-$week-$round-$level.db
+ test -r $filename && rm $filename
+ else
+ if [ $level -eq 1 ]; then
+ filename=$backup_snapshot_dir/$1-$week-0-0.db
+ else
+ filename=$backup_snapshot_dir/$1-$week-$round-$((level - 1)).db
+ fi
+ if [ -r $filename ]; then
+ cp $filename $backup_snapshot_dir/$1-$week-$round-$level.db
+ else
+ abend 1 "previous snapshot file $filename not found; cannot backup at level $level"
+ exit 1
+ fi
+ fi
+}
+
+# fs_check item
+fs_check() {
+ local rc=0
+
+ eval root=\$${1}_dir
+ eval files=\$${1}_files
+
+ test -z "$root" && rc=1 && error "${1}_dir not set"
+ test -z "$files" && rc=1 && error "${1}_files not set"
+ return $rc
+}
+
+# fs_backup item
+fs_backup() {
+ local basename text root files
+
+ basename=$1-$week-$round-$level
+ eval text=\$${1}_text
+ eval root=\$${1}_dir
+ eval files=\$${1}_files
+
+ test -z "$root" && abend 1 "${1}_dir not set"
+ test -z "$files" && abend 1 "${1}_files not set"
+ test -z "$text" && text="$1"
+ initdb $1
+ logit "backing up $text ($basename.$tar_suffix)"
+ $dry_run tar $verbose $taroptions \
+ -c -f $backup_archive_dir/$basename.$tar_suffix \
+ --listed=$backup_snapshot_dir/$basename.db \
+ -C $root $files
+ tarcode $?
+}
+
+# fs_restore item
+fs_restore() {
+ local i text root files tarcommand
+
+ eval text=\$${1}_text
+ eval root=\$${1}_dir
+ eval files=\$${1}_files
+
+ test -z "$root" && abend 1 "${1}_dir not set"
+ test -z "$files" && abend 1 "${1}_files not set"
+ test -z "$text" && text="$1"
+
+ tarcommand="tar $verbose $taroptions -C $root --listed-incremental=/dev/null -f"
+
+ logit "restoring $text"
+ logit "restoring from level 0 backup"
+
+ $dry_run $tarcommand $backup_archive_dir/$1-$week-0-0.$tar_suffix
+ tarcode $?
+
+ for i in $(seq 1 $level)
+ do
+ logit "restoring from the $round/$i backup"
+ $dry_run $tarcommand $backup_archive_dir/$1-$week-$round-$i.tar.bz2
+ tarcode $?
+ done
+ logit "finished restoring $text"
+}
+

Return to:

Send suggestions and report system problems to the System administrator.