When using scp to copy files from my server to my laptop (both running
Debian 10 and both with the same directory tree), I like to back up
the files in case I discover that I've overwritten a newer version of
a file with an older version. (I seem to make this mistake about once
or twice a year.) To this end, on my laptop I've defined the following
"get from server" function:
files="";
for file in "${@}";
do
if [[ -f $file ]]
then
cp -i -v "$file" /tmp/"$file".`date +\%Y.\%m.\%d.\%H.\%M.\%S`.backup
fi
done
for file in "${@}"
do
files="$files $(pwd | sed 's/\/home\/<username1>/\/home\/<username0>/g')/\"$file\""
done
scp -T -p <username0>@[Server IP Address]:"$files" .
If I discover that I've made a mistake, there's a backup copy in /tmp.
I'd like to be able to create backup copies on my server when sending
files in the other direction. At the moment, I have a "send to server"
function on my laptop that simply reads:
scp -p $@ <username0>@[Server IP Address]:`pwd | sed 's/\/home\/<username1>/\/home\/<username0>/g'`/
But if I accidentally copy an older version of a file on my laptop to
a newer version of the file on my server, the newer version is lost.
Is it possible to configure my server so that when it receives a remote
scp request to write to a file on the server, it parses the request
and backs up to /tmp any existing file on the server that is about to
be overwritten?
Regards,
Greg Marks