-
Notifications
You must be signed in to change notification settings - Fork 0
/
60-backup.sh
25 lines (23 loc) · 711 Bytes
/
60-backup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# Backups
require 'zstdmt' # parallel zstd
# Create a backup of a directory tree or single file.
# This is just a convenience wrapper around tar and zstd.
# The backup file is stored in the same dir as the item being backed up.
bak() {
[[ $# -eq 1 ]] || {
printf 'Usage: %s <root dir or single file to backup>\n' "$0"
return 1
}
src="${1}"
[[ -e ${src} ]] || {
printf 'Source does not exist: %s\n' "${src}"
return 1
}
dst="$(basename "${src}")-bak-$(now).tar.zstd"
[[ ! -e ${dst} ]] || {
printf 'Backup already exists: %s\n' "${dst}"
return 1
}
printf 'Creating backup: %s -> %s\n' "${src}" "${dst}"
tar --use-compress-program='zstdmt -T16' -cf "${dst}" "${src}"
}