new script for backing up any directory and storing backup file in a different directory.
authorChris Koeritz <fred@gruntose.com>
Sat, 1 Oct 2016 00:18:26 +0000 (20:18 -0400)
committerChris Koeritz <fred@gruntose.com>
Sat, 1 Oct 2016 00:18:26 +0000 (20:18 -0400)
scripts/archival/backup_arbitrary.sh [new file with mode: 0755]

diff --git a/scripts/archival/backup_arbitrary.sh b/scripts/archival/backup_arbitrary.sh
new file mode 100755 (executable)
index 0000000..ebd4b8f
--- /dev/null
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+# backs up a specific single directory by making an archive of it (tar.gz).
+# the storage location for the created archive is also specified.
+
+target_asset_path="$1"; shift
+archive_storage_path="$1"; shift
+archive_tag="$1"; shift
+
+if [ -z "$target_asset_path" -o -z "$archive_storage_path" ]; then
+  echo Backups up a directory by creating a compressed archive of it in a storage
+  echo location.
+  echo Requires the path to the folder that will be backed up as the first parameter
+  echo and the path to the archive storage directory as the second parameter.
+  exit 1
+fi
+
+# use a default archive tag if there was none provided.
+if [ -z "$archive_tag" ]; then
+  archive_tag=folder
+fi
+
+sep='_'
+
+tar -czf "${archive_storage_path}/${archive_tag}_bkup_$(date +"%Y$sep%m$sep%d$sep%H%M$sep%S" | tr -d '/\n/').tar.gz" "$target_asset_path" &>>$TMP/zz_arbitrary_backups.log
+
+