summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbackup.sh24
1 files changed, 24 insertions, 0 deletions
diff --git a/backup.sh b/backup.sh
new file mode 100755
index 0000000..6e54e8e
--- /dev/null
+++ b/backup.sh
@@ -0,0 +1,24 @@
1#!/bin/bash
2set -e
3
4[ $# -ne 3 ] && echo "Usage: $0 <dir-to-backup> <tarfile-name> <user@host:/remote/dir>" && exit 1
5
6SRC="$1"
7NAME="$2"
8DEST="$3"
9
10[ ! -d "$SRC" ] && echo "Error: '$SRC' is not a directory" && exit 1
11
12TARFILE="$(pwd)/${NAME}.tar.gz"
13
14echo "Compressing $SRC → $TARFILE"
15tar -czf "$TARFILE" -C "$(dirname "$SRC")" "$(basename "$SRC")"
16
17SIZE=$(du -h "$TARFILE" | cut -f1)
18echo "Size: $SIZE"
19
20echo "Sending to $DEST"
21rsync -avP "$TARFILE" "$DEST/"
22
23rm -f "$TARFILE"
24echo "Done"