Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > alt.os.linux > #54449
| From | Dan Purgert <dan@djph.net> |
|---|---|
| Newsgroups | alt.os.linux, alt.os.linux.mint |
| Subject | Remote backups with rsync - discussion / tutorial, I guess. |
| Followup-To | alt.os.linux |
| Date | 2019-03-15 18:19 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <slrnq8nr52.n0k.dan@djph.net> (permalink) |
Cross-posted to 2 groups.
Followups directed to: alt.os.linux
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
I know this comes up from time to time, and there are a bazillion
tutorials about it spread across the web, but it's been quiet in here
lately, and I just went through revamping my setup a few weeks ago.
Maybe someone will find it helpful.
In my case, I'm running rsync v 3.1.1, protocol version 31 (Devuan
Jessie) on my backup server, and rsync v. 3.1.2 protocol version 31 on
the clients (MX Linux & Mint 18 in a VM for testing). As such, this'll
have a definite "Debian" slant to it, apologies in advance for any
RH-specific stuff wrong.
NOTE -- for the bulk of this, we're going to assume that "source" and
"destination" are two directories on the same physical machine. The
final section will cover connecting to remote hosts.
=== Getting rsync: ===
In my experience, Debian-based distros don't tend to ship with rsync
installed; so we're just going to assume that no one ships with it.
To install, Debian style (as root):
apt-get install rsync
To install, RH style (as root):
yum install rsync
Your package manager will do its thing, and install the program for you.
=== Basic rsync operation: ===
Now that rsync is installed, we can start using it to create backups of
our stuff. Here is where things _may_ get a little annoying, especially
if you've used other methods to create backups in the past. This is
mainly caused by rsync mainly using mtime to determine whether files
have changed.
The other thing that I've seen trip people up is the syntax necessary
for getting things to work. These two commands operate slightly
differently:
rsync source destination
AND
rsync source/ destination
In the first instance, "source" will become a subdirectory under
"destination". That is, "source/file.xyz" will be saved as
"destination/source/myfile.xyz".
The second instance, only the contents of "source" will be transferred.
That is "source/file.xyz" will be saved as "destination/file.xyz".
Whether you use "source" or "source/" is up to you and how you want your
backup hierarchy to look. I use both approaches - "source" for $HOME
directories (so I get destination/myhome/[files]), and "source/" for
system things (mainly /usr/local/{,s}bin; so the backup just has
"dest/[files]".
In nearly every case, writing "source/*" is the wrong approach -- as
this'll miss dotfiles (and directories); which means potentially not
having backups of our important configs (.bashrc, .gnupg, and so on).
=== Option switches: ===
This is always the part that trips me up -- there are just so many of
them. What I have found is that for my needs, the quick and somewhat
dirty command
rsync -avP
is good for interactive mode, and I like seeing the progress indicators
(as some of the files are large, and just sitting at "/path/to/something
[...]" for 10 minutes is a bit tedious. But that's me.
In my backup scripts, I simply remove the "-P" switch, as I just like to
see the filenames being transferred (and even that's probably a bit
much)
So, what do these switches mean?
-v -> verbose. Prints the filenames as it's going, as well as some
transfer details when the process is completed.
-P -> same as "--progress". Prints progress of the transfer
-a -> "archive" mode. Same as -rlptgoD
-r -> recursively traverse directories
-l -> copy symlinks as symlinks
-p -> preserve permissions
-t -> preserve mtime
-g -> preserve group
-o -> preserve owner (only works if remote rsync is running as
super-user)
-D -> same as --devices --specials
--devices -> recreates block-devices at the remote end (only
works if remote rsync is running as super-user)
--specials -> recreates special files, such as named pipes and
fifos.
Now, in my case, my backup server isn't running rsync as root, so I lose
out on the -o and -D options as part of the archival process; but "-a"
is a lot less typing than "-rlptg".
Another option that can be extremely useful is "--exclude". However, I
tend to not use this option, as my local LAN is faster than the
internet; so better to have ~150GB of stuff locally than waiting on
steam. But that's just me.
=== Automating our backups: ===
Okay, so now we have a basic understanding of rsync, and can kick it off
at will. But, well, computers are supposed to make our lives easier,
right?
Good news, we have a scheduler on our system -- the cron daemon.
There are two ways to set up a cronjob for our backups:
1. Directly in crontab OR
2. in a script that we'll call from crontab.
Either approach is equally good here, since the backup job is pretty
much a one liner:
rsync -avP /home/youruser /backup/drive/directory
NOTE -- crontab has no concept of line breaks or line wrapping, like we
can do in bash scripts. So if you're going to need that, best to use
the second approach and do all the breaks in there.
In order to convert this to a cronjob, we should first determine when we
want the job to run, and then convert that statement into cron's syntax.
For example, let's say we want to run our backups weekly (on Sunday) at
00:30. See the next section for a quick primer on cron.
Here's our potential cronjob:
30 0 * * 0 ( rsync -avP /home/youruser /backup/drive/directory )
NOTE -> the parenthesis aren't a requirement, it's force of habit from
when I got taught how to write cronjobs.
We can add it to our user's crontab with the command "crontab -e". If
it's the first time running crontab, you'll be presented with a menu
that allows you to select your editor. Options will vary, based on your
installed editors, but will likely look like
Select an editor:
1. /bin/nano <- easiest
2. /usr/bin/vim
3. [...]
your choice[1]:
In the event you don't like your choice, you can run the "select-editor"
tool to pick another option.
=== Cron Sidebar: ===
Skip ahead if you like.
Cron uses a 5-position whitespace-delimeted time/date syntax,
corresponding to these categories:
1. Minute (0-59)
2. Hour (0-23)
3. Day of Month (i.e. 1-31)
4. Month (i.e. 1-12, or short-name - Jan,feb,mar,apr, and so on)
5. Day of Week (i.e. 0-6 --> note 1-7 also works, where 0=7=Sunday;
short names - mon,tue, etc. - work here too)
In all fields, ranges (1-n), lists (1,2,3), and combinations (1,2-6,9)
are allowed for numerical restrictions. For fields that allow text
input, you can only use lists (i.e. a range such as "mon-fri" is not
allowed).
In any field, you can use an asterisk (*) to indicate the full range.
In the event that BOTH "Day of Week" and "Day of Month" are restricted
(i.e. non-*), when EITHER "Day of Week" OR "Day of Month" is true, the
cronjob will be triggered. So, if you have for example,
30 0 15 * 5 somejob
It'll fire on every Friday AND the 15th of every month at 00:30.
=== Rsync to remote hosts: ===
Running rsync between two directories on the same local machine is great
and all, but ... well, not much of a backup. Good news though, rsync
can transport the files to a remote host with little fuss.
The easiest (and my preferred) route is to use SSH. It's as simple as
changing our basic command
rsync -avP source destination
to
rsync -avP source user@host:/path/to/destination
We can even use ssh keys
rsync -avP -e 'ssh -i /path/to/ssh/key' source user@host:/path/dest
Now, the only real downside of using ssh is that it makes the rsync
command a fair bit longer, such that it's probably not going to fit in
our "one line" crontab entry. You can, of course, let the crontab line
wrap around, but that can be ugly (and break in fun and interesting
ways).
My preferred approach is to just write a shell script, and then call
that, for example:
==== backup-etc ===
#backup /etc
name=$(hostname)
rsync -avP -e 'ssh -i /path/to/ssh_key' /etc \
user@remote:/srv/share/backups/$name/
====
and our crontab is then just something like this:
30 0 * * 0 ( /usr/local/bin/backup-etc )
Well, since you made it this far, HTH, HAND.
-----BEGIN PGP SIGNATURE-----
iQEzBAEBCAAdFiEEBcqaUD8uEzVNxUrujhHd8xJ5ooEFAlyL7KAACgkQjhHd8xJ5
ooEO5gf+KEIruTne7d+r6Gd3a8wY7k4Sf1lqQiDVFr26Ouf4VWFwEdN1jXSf3wYm
4+C8lW+6Ce/UFKT9eLK01eTXAcUGfVSzR7gfCj5kcDVfKc0C19JqfUdCjm4P8VT8
vKiwuoI9f00b2rC4CqG5fC5PWxXqZP+aR+3ixmDWR6rVkR8pRA9YL1ZBCBYyFFkE
2tmxBx1hpNLGM610tCT3OFcdsMZnQMqurEJs4SuPG1B1pxnusDpHiq7rnTs39/we
EQdunGrU1g2L60FLY1ux1Nyt/OnJ7lZitKizkFvkHqwtt8CkqLSaSYJuSnbzyTyn
sTdjGFGtxMk5RM98LqeUPAzl3fhJyg==
=jNAQ
-----END PGP SIGNATURE-----
--
|_|O|_|
|_|_|O| Github: https://github.com/dpurgert
|O|O|O| PGP: 05CA 9A50 3F2E 1335 4DC5 4AEE 8E11 DDF3 1279 A281
Back to alt.os.linux | Previous | Next — Next in thread | Find similar | Unroll thread
Remote backups with rsync - discussion / tutorial, I guess. Dan Purgert <dan@djph.net> - 2019-03-15 18:19 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. William Unruh <unruh@invalid.ca> - 2019-03-15 19:06 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. Dan Purgert <dan@djph.net> - 2019-03-18 11:13 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. William Unruh <unruh@invalid.ca> - 2019-03-18 16:40 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. Dan Purgert <dan@djph.net> - 2019-03-19 10:24 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. Mike Easter <MikeE@ster.invalid> - 2019-03-15 16:17 -0700
Re: Remote backups with rsync - discussion / tutorial, I guess. jjb <invalid@invalid.nl> - 2019-03-16 10:14 +0100
Re: Remote backups with rsync - discussion / tutorial, I guess. Chris Elvidge <chris@mshome.net> - 2019-03-16 09:26 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. William Unruh <unruh@invalid.ca> - 2019-03-16 16:54 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. Richard Kettlewell <invalid@invalid.invalid> - 2019-03-16 16:57 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. Richard Kettlewell <invalid@invalid.invalid> - 2019-03-16 11:06 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. gazelle@shell.xmission.com (Kenny McCormack) - 2019-03-17 12:52 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. Allodoxaphobia <trepidation@example.net> - 2019-03-17 17:32 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. Java Jive <java@evij.com.invalid> - 2019-03-18 12:29 +0000
DOS/Windows "COPY" command (Was: Remote backups with rsync - discussion / tutorial, I guess.) gazelle@shell.xmission.com (Kenny McCormack) - 2019-03-18 16:32 +0000
Re: DOS/Windows "COPY" command (Was: Remote backups with rsync - discussion / tutorial, I guess.) Java Jive <java@evij.com.invalid> - 2019-03-18 16:40 +0000
Re: DOS/Windows "COPY" command (Was: Remote backups with rsync - discussion / tutorial, I guess.) "R.Wieser" <address@not.available> - 2019-03-18 17:59 +0100
Re: DOS/Windows "COPY" command (Was: Remote backups with rsync - discussion / tutorial, I guess.) Adrian Caspersz <email@here.invalid> - 2019-03-18 17:51 +0000
Re: DOS/Windows "COPY" command (Was: Remote backups with rsync - discussion / tutorial, I guess.) "R.Wieser" <address@not.available> - 2019-03-18 19:00 +0100
Re: DOS/Windows "COPY" command (Was: Remote backups with rsync - discussion / tutorial, I guess.) "Carlos E.R." <robin_listas@es.invalid> - 2019-03-18 20:16 +0100
Re: DOS/Windows "COPY" command (Was: Remote backups with rsync - discussion / tutorial, I guess.) Dan Purgert <dan@djph.net> - 2019-03-19 10:19 +0000
Re: DOS/Windows "COPY" command (Was: Remote backups with rsync - discussion / tutorial, I guess.) "Carlos E.R." <robin_listas@es.invalid> - 2019-03-19 12:06 +0100
Re: DOS/Windows "COPY" command (Was: Remote backups with rsync - discussion / tutorial, I guess.) Dan Purgert <dan@djph.net> - 2019-03-19 12:42 +0000
Re: DOS/Windows "COPY" command (Was: Remote backups with rsync - discussion / tutorial, I guess.) "Carlos E.R." <robin_listas@es.invalid> - 2019-03-19 19:36 +0100
Re: DOS/Windows "COPY" command (Was: Remote backups with rsync - discussion / tutorial, I guess.) Dan Purgert <dan@djph.net> - 2019-03-20 10:17 +0000
Re: DOS/Windows "COPY" command (Was: Remote backups with rsync - discussion / tutorial, I guess.) Java Jive <java@evij.com.invalid> - 2019-03-19 13:24 +0000
Re: DOS/Windows "COPY" command (Was: Remote backups with rsync - discussion / tutorial, I guess.) "Carlos E.R." <robin_listas@es.invalid> - 2019-03-19 19:38 +0100
Re: Remote backups with rsync - discussion / tutorial, I guess. Adrian Caspersz <email@here.invalid> - 2019-03-18 17:47 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. William Unruh <unruh@invalid.ca> - 2019-03-19 00:29 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. Chris Elvidge <chris@mshome.net> - 2019-03-19 09:02 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. "Carlos E.R." <robin_listas@es.invalid> - 2019-03-19 12:07 +0100
Re: Remote backups with rsync - discussion / tutorial, I guess. gazelle@shell.xmission.com (Kenny McCormack) - 2019-03-19 13:57 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. "Carlos E.R." <robin_listas@es.invalid> - 2019-03-19 19:45 +0100
Re: Remote backups with rsync - discussion / tutorial, I guess. Richard Kettlewell <invalid@invalid.invalid> - 2019-03-20 08:52 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. "Carlos E.R." <robin_listas@es.invalid> - 2019-03-20 11:24 +0100
Re: Remote backups with rsync - discussion / tutorial, I guess. gazelle@shell.xmission.com (Kenny McCormack) - 2019-03-20 11:31 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. William Unruh <unruh@invalid.ca> - 2019-03-20 15:03 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. gazelle@shell.xmission.com (Kenny McCormack) - 2019-03-20 17:05 +0000
Why I don't like "rsync"... (Was: Remote backups with rsync - discussion / tutorial, I guess.) gazelle@shell.xmission.com (Kenny McCormack) - 2019-03-20 12:08 +0000
Re: Why I don't like "rsync"... (Was: Remote backups with rsync - discussion / tutorial, I guess.) Chris Elvidge <chris@mshome.net> - 2019-03-20 13:04 +0000
Re: Why I don't like "rsync"... Richard Kettlewell <invalid@invalid.invalid> - 2019-03-20 13:47 +0000
Re: Why I don't like "rsync"... "Carlos E.R." <robin_listas@es.invalid> - 2019-03-22 19:41 +0100
Re: Why I don't like "rsync"... gazelle@shell.xmission.com (Kenny McCormack) - 2019-03-24 09:36 +0000
Re: Why I don't like "rsync"... Richard Kettlewell <invalid@invalid.invalid> - 2019-03-24 09:59 +0000
Re: Why I don't like "rsync"... gazelle@shell.xmission.com (Kenny McCormack) - 2019-03-24 10:36 +0000
Re: Why I don't like "rsync"... Richard Kettlewell <invalid@invalid.invalid> - 2019-03-24 11:12 +0000
Re: Why I don't like "rsync"... gazelle@shell.xmission.com (Kenny McCormack) - 2019-03-24 11:29 +0000
Re: Why I don't like "rsync"... Richard Kettlewell <invalid@invalid.invalid> - 2019-03-24 13:04 +0000
Re: Why I don't like "rsync"... gazelle@shell.xmission.com (Kenny McCormack) - 2019-03-24 13:16 +0000
Re: Why I don't like "rsync"... Dan Purgert <dan@djph.net> - 2019-03-25 10:37 +0000
Re: Why I don't like "rsync"... (Was: Remote backups with rsync - discussion / tutorial, I guess.) William Unruh <unruh@invalid.ca> - 2019-03-20 15:19 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. Dan Purgert <dan@djph.net> - 2019-03-20 12:44 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. Richard Kettlewell <invalid@invalid.invalid> - 2019-03-20 13:58 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. Dan Purgert <dan@djph.net> - 2019-03-20 15:00 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. Richard Kettlewell <invalid@invalid.invalid> - 2019-03-20 15:49 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. William Unruh <unruh@invalid.ca> - 2019-03-20 17:57 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. Richard Kettlewell <invalid@invalid.invalid> - 2019-03-20 23:39 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. Jasen Betts <jasen@xnet.co.nz> - 2019-03-21 08:15 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. Richard Kettlewell <invalid@invalid.invalid> - 2019-03-21 09:00 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. gazelle@shell.xmission.com (Kenny McCormack) - 2019-03-21 13:11 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. Dan Purgert <dan@djph.net> - 2019-03-21 14:03 +0000
rsync --archive Ivan Shmakov <ivan@siamics.net> - 2019-03-21 18:10 +0000
Re: rsync --archive Richard Kettlewell <invalid@invalid.invalid> - 2019-03-21 21:42 +0000
Re: rsync --archive "Carlos E.R." <robin_listas@es.invalid> - 2019-03-22 19:54 +0100
Re: rsync --archive Ivan Shmakov <ivan@miko.siamics.net> - 2019-03-23 04:32 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. William Unruh <unruh@invalid.ca> - 2019-03-21 18:54 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. Jasen Betts <jasen@xnet.co.nz> - 2019-03-22 10:03 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. William Unruh <unruh@invalid.ca> - 2019-03-21 18:50 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. Richard Kettlewell <invalid@invalid.invalid> - 2019-03-21 21:31 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. "Carlos E.R." <robin_listas@es.invalid> - 2019-03-22 19:48 +0100
Re: Remote backups with rsync - discussion / tutorial, I guess. William Unruh <unruh@invalid.ca> - 2019-03-20 15:07 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. William Unruh <unruh@invalid.ca> - 2019-03-20 14:57 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. Richard Kettlewell <invalid@invalid.invalid> - 2019-03-20 15:54 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. William Unruh <unruh@invalid.ca> - 2019-03-20 17:49 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. Jasen Betts <jasen@xnet.co.nz> - 2019-03-21 08:21 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. Jasen Betts <jasen@xnet.co.nz> - 2019-03-19 20:50 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. William Unruh <unruh@invalid.ca> - 2019-03-20 02:40 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. gazelle@shell.xmission.com (Kenny McCormack) - 2019-03-20 08:19 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. William Unruh <unruh@invalid.ca> - 2019-03-20 02:37 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. Jasen Betts <jasen@xnet.co.nz> - 2019-03-19 19:53 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. "Carlos E.R." <robin_listas@es.invalid> - 2019-03-19 21:25 +0100
Re: Remote backups with rsync - discussion / tutorial, I guess. Java Jive <java@evij.com.invalid> - 2019-03-19 22:04 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. Dan Purgert <dan@djph.net> - 2019-03-18 11:20 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. "Carlos E.R." <robin_listas@es.invalid> - 2019-03-18 13:07 +0100
Re: Remote backups with rsync - discussion / tutorial, I guess. Dan Purgert <dan@djph.net> - 2019-03-18 12:43 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. "Carlos E.R." <robin_listas@es.invalid> - 2019-03-18 14:32 +0100
Re: Remote backups with rsync - discussion / tutorial, I guess. William Unruh <unruh@invalid.ca> - 2019-03-18 16:44 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. Daniel60 <daniel47@eternal-september.org> - 2019-03-16 23:52 +1100
Re: Remote backups with rsync - discussion / tutorial, I guess. Dan Purgert <dan@djph.net> - 2019-03-18 11:49 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. "Carlos E.R." <robin_listas@es.invalid> - 2019-03-18 13:11 +0100
Re: Remote backups with rsync - discussion / tutorial, I guess. Dan Purgert <dan@djph.net> - 2019-03-18 12:45 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. William Unruh <unruh@invalid.ca> - 2019-03-18 18:12 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. Chris Elvidge <chris@mshome.net> - 2019-03-18 19:12 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. Chris Elvidge <chris@mshome.net> - 2019-03-18 19:19 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. Daniel60 <daniel47@eternal-september.org> - 2019-04-02 22:37 +1100
Re: Remote backups with rsync - discussion / tutorial, I guess. jjb <invalid@invalid.nl> - 2019-03-19 12:49 +0100
Re: Remote backups with rsync - discussion / tutorial, I guess. Jasen Betts <jasen@xnet.co.nz> - 2019-03-19 21:08 +0000
Re: Remote backups with rsync - discussion / tutorial, I guess. jjb <invalid@invalid.nl> - 2019-03-20 12:51 +0100
Re: Remote backups with rsync - discussion / tutorial, I guess. jjb <invalid@invalid.nl> - 2019-03-20 10:37 +0100
Re: Remote backups with rsync - discussion / tutorial, I guess. jjb <invalid@invalid.nl> - 2019-03-20 12:53 +0100
csiph-web