1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-06-25 16:57:12 -07:00
rc/sh/baks

27 lines
581 B
Plaintext
Raw Normal View History

2021-07-29 00:37:35 -07:00
#!/usr/bin/env sh
2021-07-31 16:15:27 -07:00
# backup, timestamped
2021-07-29 00:37:35 -07:00
# YES_ZSH
# YES_BASH
# YES_DASH
2021-07-29 00:37:35 -07:00
: $((SOURCING+=1))
2021-07-29 00:37:35 -07:00
#. ~/sh/note # FIXME: don't do this?
: $((SOURCING-=1))
2021-07-29 00:37:35 -07:00
baks() { ### @-
2021-07-29 00:37:35 -07:00
local ret=0
for fp; do
local now="$(date -u '+%y-%m-%d_%H-%M-%S')"
local bak="$fp.$now.bak"
if [ -s "$bak" ]; then
#note "how in the hell?" "$bak" "already exists"
printf "%s %s %s\n" "how in the hell?" "$bak" "already exists"
2021-07-29 00:37:35 -07:00
ret=1
fi
cp -p "$fp" "$bak" || ret=1
done
return $ret
}
[ "${SOURCING:-0}" -gt 0 ] || baks "$@"