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
|
2021-07-29 05:44:12 -07:00
|
|
|
# YES_BASH
|
|
|
|
# YES_DASH
|
2021-07-29 00:37:35 -07:00
|
|
|
|
2021-08-01 07:58:21 -07:00
|
|
|
#: $((SOURCING+=1))
|
2021-07-29 00:37:35 -07:00
|
|
|
#. ~/sh/note # FIXME: don't do this?
|
2021-08-01 07:58:21 -07:00
|
|
|
#: $((SOURCING-=1))
|
2021-07-29 00:37:35 -07:00
|
|
|
|
2021-07-30 19:41:16 -07:00
|
|
|
baks() { ### @-
|
2021-08-01 07:58:21 -07:00
|
|
|
### backup files by copying each and appending *the current* date-time,
|
|
|
|
### irrespective of when the files were modified or created.
|
|
|
|
###
|
|
|
|
### ```
|
|
|
|
### $ touch -d '2001-12-25 16:30:00' butts
|
|
|
|
### $ baks butts
|
|
|
|
### $ baks butts
|
|
|
|
### $ ls -l
|
|
|
|
### total 0
|
|
|
|
### -rw-r--r-- 1 notwa None 0 Dec 25 2001 butts
|
|
|
|
### -rw-r--r-- 1 notwa None 0 Dec 25 2001 butts.21-08-01_14-54-07.bak
|
|
|
|
### -rw-r--r-- 1 notwa None 0 Dec 25 2001 butts.21-08-01_14-54-09.bak
|
|
|
|
### ```
|
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
|
2021-07-29 05:44:12 -07:00
|
|
|
#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 "$@"
|