Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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 :
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".
Last edited by berndbausch; 11-05-2020 at 08:41 AM.
Reason: additional info
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...
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
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.
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.
'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) .
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.