Add args to borg script
This commit is contained in:
parent
a2a8158087
commit
1502743b54
1 changed files with 33 additions and 9 deletions
|
@ -1,16 +1,40 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# We only want this file to be executed at most once per day, so we stat a cache
|
###
|
||||||
# file before running the rest of the code
|
### arch-desktop_borg.sh
|
||||||
cache_file='/home/flyingscorpio/.cache/borg_backup_hook_last_executed'
|
###
|
||||||
if [ -f "$cache_file" ]; then
|
### Usage:
|
||||||
cache_stat=$(stat -c %y "$cache_file" | cut -d' ' -f1)
|
### "$0" [-f]
|
||||||
today=$(date +%Y-%m-%d)
|
###
|
||||||
if [ "$cache_stat" = "$today" ]; then
|
### Options:
|
||||||
echo "The borg backup was already executed today" && exit 0
|
### -f Force an update, even if one was already made today.
|
||||||
|
### -h Print this help message and quit.
|
||||||
|
###
|
||||||
|
|
||||||
|
|
||||||
|
print_help() {
|
||||||
|
awk -F'### ' '/^###/ { print $2 }' "$0"
|
||||||
|
}
|
||||||
|
|
||||||
|
stat_cache_file() {
|
||||||
|
# We only want this file to be executed at most once per day, so we stat a cache
|
||||||
|
# file before running the rest of the code
|
||||||
|
cache_file='/home/flyingscorpio/.cache/borg_backup_hook_last_executed'
|
||||||
|
if [ -f "$cache_file" ]; then
|
||||||
|
cache_stat=$(stat -c %y "$cache_file" | cut -d' ' -f1)
|
||||||
|
today=$(date +%Y-%m-%d)
|
||||||
|
if [ "$cache_stat" = "$today" ]; then
|
||||||
|
echo "The borg backup was already executed today" && exit 0
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
touch "$cache_file"
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ "$1" = '-h' ]; then
|
||||||
|
print_help && exit 1
|
||||||
fi
|
fi
|
||||||
touch "$cache_file"
|
|
||||||
|
[ "$1" = '-f' ] || stat_cache_file
|
||||||
|
|
||||||
# Setting this so the repo does not need to be given on the command line:
|
# Setting this so the repo does not need to be given on the command line:
|
||||||
BORG_REPO=ssh://flyingscorpio@2px.info:22/~/"$(hostname)".borg
|
BORG_REPO=ssh://flyingscorpio@2px.info:22/~/"$(hostname)".borg
|
||||||
|
|
Loading…
Add table
Reference in a new issue