LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   rsync equivalent to mv --backup=numbered (https://www.linuxquestions.org/questions/linux-server-73/rsync-equivalent-to-mv-backup%3Dnumbered-4175684742/)

ychaouche 11-05-2020 06:27 AM

rsync equivalent to mv --backup=numbered
 
Dear LQ,

How do you rsync files to remote location AND save a backup copy of overwritten files ? I was hoping to find something similar to mv's --backup=numbered version. The end result on the target host would look like :

file.1
file.2
file.3

berndbausch 11-05-2020 08:38 AM

From the rsync manual page:
Quote:

--backup, -b

With this option, preexisting destination files are renamed as
each file is transferred or deleted. You can control where
the backup file goes and what (if any) suffix gets appended
using the --backup-dir and --suffix options.
This is not quite what you want. I don't know if it is possible to create several versions of old destination files like in your example, but the continuation of the above paragraph contains the sentence "This will prevent previously backed-up files from being deleted".

syg00 11-05-2020 04:41 PM

Not the function of rsync. A simple search should have turned up rsnapshot or its contemporaries.

chrism01 11-05-2020 11:26 PM

Taking a slightly lateral approach, it looks a bit like you want a different backup for eg each day ?
In which case, use target dirs named for each day (or date etc), which means you'd always have a 'few' backups/originals.
It really depends on the exact effect you are after; keep 2 systems in sync+backups, or just backups...

scasey 11-05-2020 11:30 PM

+1 for rsnapshot...an easy to configure wrapper for rsync to create/maintain multi-generational backups.

ychaouche 11-08-2020 02:32 AM

Quote:

Originally Posted by syg00 (Post 6182241)
Not the function of rsync. A simple search should have turned up rsnapshot or its contemporaries.

Not the function of mv too I suppose.

ychaouche 11-08-2020 02:34 AM

Quote:

Originally Posted by chrism01 (Post 6182335)
Taking a slightly lateral approach, it looks a bit like you want a different backup for eg each day ?
In which case, use target dirs named for each day (or date etc)

It's the closest solution I have found, but that means hacking the --backup-dir option with a $(date --some-options) for eg.

Quote:

Originally Posted by chrism01 (Post 6182335)
It really depends on the exact effect you are after; keep 2 systems in sync+backups, or just backups...

A simple file copy from A to B, while keeping B's original file. I turned to rsync since OpenSSH says not to use scp anymore.

sgosnell 11-08-2020 02:00 PM

So why not just use cp? You could write a script, or just put the entire statement in the crontab. I think a script would be preferable. Get the day of the week, use that as a variable to choose the folder to receive the cp.

chrism01 11-08-2020 11:07 PM

'cp' just works locally (unless you pipe through netcat / nc ?).
Apart from that though, yes - grab the day name from the date cmd and write a script for cron to call.

Otoh, if you literally just want to backup some files from A to B, and overwrite previous copies (without disturbing B copy of the files), then the above sans the 'day' bit.

Just designate a dir on B to save A's files and rsync or whatever to there.
You could even mount the dir on B onto A and use a 'local' cp ;)

If you want secure, see sshfs :)

PS I'm assuming the machines are 'close enough' that remote mounting is practical (think timeouts on long distance cxns) .

ychaouche 11-09-2020 02:11 AM

Thank you all folks, the easiest would be to use rsync --backup-dir, but if I take only the "day" portion of it that means I can only have a single backup per day. Anyway, marking this as solved.

sgosnell 11-09-2020 10:06 AM

If you want to back up more often than once per day, there are ways to do that. You could do it hourly and have a directory for each hour. You can get the hour of the day easily enough. Or just name the directory with a number which rotates between 1 and the number of backups you want. 1.1, 1.2, etc. It depends on the frequency of backups, and the number you want to keep.

ychaouche 11-10-2020 02:54 AM

Quote:

Originally Posted by sgosnell (Post 6183668)
Or just name the directory with a number which rotates between 1 and the number of backups you want

Exactly what my question asks, and exactly what mv --backup=numbered does.


All times are GMT -5. The time now is 08:02 PM.