aboutsummaryrefslogtreecommitdiff
path: root/daily-snapshot.sh
diff options
context:
space:
mode:
authorTrey Bastian <hello@treybastian.com>2025-11-19 11:21:25 +0000
committerTrey Bastian <hello@treybastian.com>2025-11-19 11:21:25 +0000
commit30a5e12dfe12728c1dd7b7eb455dd23919fe7305 (patch)
treeba09ec0eae78d7521997a5bc754d59cadbf49ed3 /daily-snapshot.sh
parent165f78c96d37a5801b1fc3c03d5a8208f82da319 (diff)
added my backup scripts
Diffstat (limited to 'daily-snapshot.sh')
-rwxr-xr-xdaily-snapshot.sh25
1 files changed, 25 insertions, 0 deletions
diff --git a/daily-snapshot.sh b/daily-snapshot.sh
new file mode 100755
index 0000000..cb8e0b6
--- /dev/null
+++ b/daily-snapshot.sh
@@ -0,0 +1,25 @@
+#!/bin/bash
+#
+# This script will gzip /mnt/backup/live/
+# This script assumes /mnt/backup/snapshots/ is where we want to store archives
+# This script will only keep 7 days worth of archives
+# -- if you want to change this just change `MAX_BACKUPS`
+#
+# My personal setup:
+# -- has this running daily with cron at 00:30z
+# -- mounts /mnt/backup to it's own specific NFS share configured for the host
+#
+
+MAX_BACKUPS=7
+
+tar -czf "/mnt/backup/snapshots/gwaine.snapshot.`date + "%FT%H%M%S"`.tar.gz" -C /mnt/backup/live .
+
+COUNT=$(ls -1 /mnt/backup/snapshots/*.tar.gz 2>/dev/null | wc -l)
+
+if [ "$COUNT" -gt $MAX_BACKUPS]; then
+ # why not just delete the oldest file only Trey???
+ # well I'll tell you why! If I want to change MAX_BACKUPS from 7 to 3
+ # I'll have a whole bunch of extra archives I don't want to keep
+ EXTRA=$((COUNT - MAX_BACKUPS))
+ ls -1T /mnt/backup/snapshots/*.tar.gz | tail -n "$EXTRA" | xargs rm -f
+fi