add tar backup
authorAndrew Lorimer <andrew@lorimer.id.au>
Sun, 8 Nov 2020 12:08:27 +0000 (23:08 +1100)
committerAndrew Lorimer <andrew@lorimer.id.au>
Sun, 8 Nov 2020 12:08:27 +0000 (23:08 +1100)
tar-backup.sh [new file with mode: 0755]
diff --git a/tar-backup.sh b/tar-backup.sh
new file mode 100755 (executable)
index 0000000..43f5741
--- /dev/null
@@ -0,0 +1,40 @@
+#!/bin/bash
+# full system backup
+# taken from Arch Wiki:
+# https://wiki.archlinux.org/index.php/Full_system_backup_with_tar
+
+# Backup destination
+backdest=/backup
+
+# Labels for backup name
+#PC=${HOSTNAME}
+pc=ruslan
+distro=arch
+type=full
+date=$(date "+%F")
+backupfile="$backdest/$distro-$type-$date.tar.gz"
+
+# Exclude file location
+prog=${0##*/} # Program name from filename
+excdir="/home/<user>/.bin/root/backup"
+exclude_file="$excdir/$prog-exc.txt"
+
+# Check if chrooted prompt.
+echo -n "First chroot from a LiveCD.  Are you ready to backup? (y/n): "
+read executeback
+
+# Check if exclude file exists
+if [ ! -f $exclude_file ]; then
+  echo -n "No exclude file exists, continue? (y/n): "
+  read continue
+  if [ $continue == "n" ]; then exit; fi
+fi
+
+if [ $executeback = "y" ]; then
+  # -p and --xattrs store all permissions and extended attributes. 
+  # Without both of these, many programs will stop working!
+  # It is safe to remove the verbose (-v) flag. If you are using a 
+  # slow terminal, this can greatly speed up the backup process.
+  tar --exclude-from=$exclude_file --xattrs -czpvf $backupfile /
+fi
+