diff options
| author | Your Name <you@example.com> | 2026-02-19 23:08:55 +0800 |
|---|---|---|
| committer | Your Name <you@example.com> | 2026-02-19 23:08:55 +0800 |
| commit | be5699a8da55d30fa309743a03a8aca2d1662403 (patch) | |
| tree | c04fad9b35c59008e597a7249c010d9b1b9e97f5 | |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| -rwxr-xr-x | backup.sh | 24 |
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 | ||
| 2 | set -e | ||
| 3 | |||
| 4 | [ $# -ne 3 ] && echo "Usage: $0 <dir-to-backup> <tarfile-name> <user@host:/remote/dir>" && exit 1 | ||
| 5 | |||
| 6 | SRC="$1" | ||
| 7 | NAME="$2" | ||
| 8 | DEST="$3" | ||
| 9 | |||
| 10 | [ ! -d "$SRC" ] && echo "Error: '$SRC' is not a directory" && exit 1 | ||
| 11 | |||
| 12 | TARFILE="$(pwd)/${NAME}.tar.gz" | ||
| 13 | |||
| 14 | echo "Compressing $SRC → $TARFILE" | ||
| 15 | tar -czf "$TARFILE" -C "$(dirname "$SRC")" "$(basename "$SRC")" | ||
| 16 | |||
| 17 | SIZE=$(du -h "$TARFILE" | cut -f1) | ||
| 18 | echo "Size: $SIZE" | ||
| 19 | |||
| 20 | echo "Sending to $DEST" | ||
| 21 | rsync -avP "$TARFILE" "$DEST/" | ||
| 22 | |||
| 23 | rm -f "$TARFILE" | ||
| 24 | echo "Done" | ||
