mirror of
https://github.com/notwa/rc
synced 2024-11-13 19:59:02 -08:00
35 lines
1.1 KiB
Bash
Executable file
35 lines
1.1 KiB
Bash
Executable file
#!/usr/bin/env sh
|
|
# backup, timestamped
|
|
# compat: +ash +bash +dash -hush -ksh +mksh +oksh +osh +posh +yash +zsh
|
|
|
|
baks() { ### @-
|
|
### 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
|
|
### ```
|
|
local ret=0 fp=
|
|
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"
|
|
ret=1
|
|
fi
|
|
cp -p "$fp" "$bak" || ret=1
|
|
done
|
|
return $ret
|
|
}
|
|
|
|
[ -n "${preload+-}" ] || . ~/sh/preload || exit 2
|
|
eval ${preload:-preload} note
|
|
[ -n "${preload+-}" ] || baks "$@"
|