Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #219523

Re: scp overwriting precaution?

From David Christensen <dpchrist@holgerdanske.com>
Newsgroups linux.debian.user
Subject Re: scp overwriting precaution?
Date 2020-02-27 07:00 +0100
Message-ID <zEknf-a1-3@gated-at.bofh.it> (permalink)
References <zEiv7-7rp-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On 2020-02-26 19:48, Greg Marks wrote:
> 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


My preferred solution is ZFS and zfs-auto-snapshot.  You set up a cron 
job and snapshots/ cleaning take place automatically according to 
whatever time schedules and retention counts you pick.  If you damage or 
destroy files or directories, the '/.zfs/snapshot' directory is your 
friend.  If you inflict mass damage on your filesystem, the 'zfs 
rollback' command is your friend.


When you have two or more ZFS pools and/or machines, you can use 
replication to backup entire filesystems, including snapshots, clones, etc..


I switched to FreeBSD on my SOHO CVS and Samba server about a year ago. 
ZFS boot, encrypted swap, and encrypted ZFS root are all installer 
options, which makes for a very nice OOTB experience.


I have been using Debian GNU/Linux for many years, first with ext* 
filesystems, then btrfs, and now ext4.  I recently started experimenting 
with ZFS on Linux (ZOL) via the following packages:

     zfs-auto-snapshot
     zfs-dkms
     zfsutils-linux


apt-get pulled in most of the required packages, but licensing requires 
ZFS to be built and the build failed.  STFW I realized that I needed to 
install linux-headers-amd64 (choose the correct package for your 
architecture).  I believe I uninstalled zfs-dkms and then installed 
again to get everything to finish correctly.  If ZOL works, I may 
migrate /home.


David

Back to linux.debian.user | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

scp overwriting precaution? Greg Marks <gtmarks@gmail.com> - 2020-02-27 05:00 +0100
  Re: scp overwriting precaution? Will Mengarini <seldon@eskimo.com> - 2020-02-27 06:20 +0100
  Re: scp overwriting precaution? David Christensen <dpchrist@holgerdanske.com> - 2020-02-27 07:00 +0100
  Re: scp overwriting precaution? Jochen Spieker <ml@well-adjusted.de> - 2020-02-27 11:30 +0100
  Re: scp overwriting precaution? Jonathan Dowland <jon+debian-user@dow.land> - 2020-02-27 11:30 +0100
  Re: scp overwriting precaution? Dan Purgert <dan@djph.net> - 2020-02-27 13:50 +0100
  Re: scp overwriting precaution? Greg Wooledge <wooledg@eeg.ccf.org> - 2020-02-27 15:10 +0100
  Re: scp overwriting precaution? Charles Curley <charlescurley@charlescurley.com> - 2020-02-27 15:10 +0100

csiph-web