LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 11-05-2020, 06:27 AM   #1
ychaouche
Member
 
Registered: Mar 2017
Distribution: Mint, Debian, Q4OS, Mageia, KDE Neon
Posts: 364
Blog Entries: 1

Rep: Reputation: 47
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
 
Old 11-05-2020, 08:38 AM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
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".

Last edited by berndbausch; 11-05-2020 at 08:41 AM. Reason: additional info
 
Old 11-05-2020, 04:41 PM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,103

Rep: Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117Reputation: 4117
Not the function of rsync. A simple search should have turned up rsnapshot or its contemporaries.
 
1 members found this post helpful.
Old 11-05-2020, 11:26 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,348

Rep: Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749
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...

Last edited by chrism01; 11-05-2020 at 11:30 PM.
 
Old 11-05-2020, 11:30 PM   #5
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,708

Rep: Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210Reputation: 2210
+1 for rsnapshot...an easy to configure wrapper for rsync to create/maintain multi-generational backups.
 
1 members found this post helpful.
Old 11-08-2020, 02:32 AM   #6
ychaouche
Member
 
Registered: Mar 2017
Distribution: Mint, Debian, Q4OS, Mageia, KDE Neon
Posts: 364

Original Poster
Blog Entries: 1

Rep: Reputation: 47
Quote:
Originally Posted by syg00 View Post
Not the function of rsync. A simple search should have turned up rsnapshot or its contemporaries.
Not the function of mv too I suppose.
 
Old 11-08-2020, 02:34 AM   #7
ychaouche
Member
 
Registered: Mar 2017
Distribution: Mint, Debian, Q4OS, Mageia, KDE Neon
Posts: 364

Original Poster
Blog Entries: 1

Rep: Reputation: 47
Quote:
Originally Posted by chrism01 View Post
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 View Post
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.

Last edited by ychaouche; 11-08-2020 at 02:37 AM.
 
Old 11-08-2020, 02:00 PM   #8
sgosnell
Senior Member
 
Registered: Jan 2008
Location: Baja Oklahoma
Distribution: Debian Stable and Unstable
Posts: 1,943

Rep: Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542
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.
 
Old 11-08-2020, 11:07 PM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,348

Rep: Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749Reputation: 2749
'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) .
 
Old 11-09-2020, 02:11 AM   #10
ychaouche
Member
 
Registered: Mar 2017
Distribution: Mint, Debian, Q4OS, Mageia, KDE Neon
Posts: 364

Original Poster
Blog Entries: 1

Rep: Reputation: 47
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.
 
Old 11-09-2020, 10:06 AM   #11
sgosnell
Senior Member
 
Registered: Jan 2008
Location: Baja Oklahoma
Distribution: Debian Stable and Unstable
Posts: 1,943

Rep: Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542Reputation: 542
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.
 
Old 11-10-2020, 02:54 AM   #12
ychaouche
Member
 
Registered: Mar 2017
Distribution: Mint, Debian, Q4OS, Mageia, KDE Neon
Posts: 364

Original Poster
Blog Entries: 1

Rep: Reputation: 47
Quote:
Originally Posted by sgosnell View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Equivalent to --remove-source-files for rsync in older versions of rsync anon091 Linux - Server 7 08-11-2016 10:30 AM
Your (patent) paydays are numbered! Hitboxx General 2 08-22-2007 03:14 PM
Download consecutively numbered files patrokov Programming 15 08-23-2006 07:13 AM
Numbered headings in XHTML vharishankar Programming 6 08-07-2005 01:12 AM
Numbered Keypad doesn't funtion. l0f33t Linux - Hardware 1 05-25-2003 11:16 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 04:56 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration