LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 02-18-2021, 02:45 AM   #1
dchmelik
Senior Member
 
Registered: Nov 2008
Location: USA
Distribution: Slackware, FreeBSD, Illumos, NetBSD, DragonflyBSD, Plan9, Inferno, OpenBSD, FreeDOS, HURD
Posts: 1,073

Rep: Reputation: 148Reputation: 148
Question rsync backup over network?


I'm trying to do a complicated rsync backup of a home directory on a local area network (LAN.) I need to exclude some directories but in some cases that doesn't work. Unfortunately some also have spaces (which I learned can still be backed up by escaping the slash twice.) I saw examples on various question & answer sites of how to exclude them but there was a lot of speculation and sloppy writing, so nothing there worked. I'm able to exclude directories one level in like /home/user/directory1 (can exclude directory1) but not multiple levels in like /home/user/directory1/directory2 (however I try to exclude directory2, even if it doesn't have spaces, it always gets copied.) What's the exact way to do that, or is there an easier way to list exclusions in an exclude_file.txt, --exclude-from=exclude_file.txt and what would be the format of such a file (also in the case of directories with spaces?)

My recent command was something like the following (in which /home/user/directory1/directory2/directory3 always was copied) (I did this in several steps.)

Code:
rsync -av --info=progress2 --delete --exclude=directory2/directory3 sourcehost:/home/user/directory1/ /home/user/directory1

Last edited by dchmelik; 02-18-2021 at 02:53 AM.
 
Old 02-18-2021, 06:31 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
Quote:
Originally Posted by dchmelik View Post
spaces (which I learned can still be backed up by escaping the slash twice.)
Well, by putting a backslash in front of the space, or quotes around the directory name.

Quote:
is there an easier way to list exclusions in an exclude_file.txt, --exclude-from=exclude_file.txt and what would be the format of such a file (also in the case of directories with spaces?)
If you have more than a handful of directories you want to exclude, a file is the better approach. One directory per line, and I don't even think quotes or backslashes are needed (I am not sure; double-check this, please).
Quote:
My recent command was something like the following (in which /home/user/directory1/directory2/directory3 always was copied) (I did this in several steps.)
Code:
rsync -av --info=progress2 --delete --exclude=directory2/directory3 sourcehost:/home/user/directory1/ /home/user/directory1
If you start the rsync at /home/user/directory1, excluding directory2/directory3 has no effect indeed, because no directory with that name would be copied.

My last statement may be incorrect.

Last edited by berndbausch; 02-18-2021 at 06:38 AM.
 
Old 02-18-2021, 09:02 AM   #3
HappyTux
Senior Member
 
Registered: Mar 2003
Location: Nova Scotia, Canada
Distribution: Debian AMD64
Posts: 4,170

Rep: Reputation: 244Reputation: 244Reputation: 244
Here is what I use to backup my Pi to another SSD, works flawlessly, for an example of multiple excludes.

Code:
rsync -ahPHAXx --delete --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/home/seeder1/rtorrent/*,/lost+found} / /tmp/ssdroot/
An example of a working exclude file to stop my Apple . files from being copied when using rsync it includes directories with spaces in it.

Code:
MacUser2525:~$ alias rsa
alias rsa="rsync -avP --exclude-from=‘/Users/MacUser2525/Bin/apple_exclude.txt'"

MacUser2525:~$ cat Bin/apple_exclude.txt

.Trashes
._.Trashes
.fseventsd
.Spotlight-V100
.DS_Store
.AppleDesktop
.AppleDB
Network Trash Folder
Temporary Items
 
1 members found this post helpful.
Old 02-18-2021, 03:41 PM   #4
dchmelik
Senior Member
 
Registered: Nov 2008
Location: USA
Distribution: Slackware, FreeBSD, Illumos, NetBSD, DragonflyBSD, Plan9, Inferno, OpenBSD, FreeDOS, HURD
Posts: 1,073

Original Poster
Rep: Reputation: 148Reputation: 148
Quote:
Originally Posted by berndbausch View Post
If you start the rsync at /home/user/directory1, excluding directory2/directory3 has no effect indeed, because no directory with that name would be copied.

My last statement may be incorrect.
Yes, it is incorrect, because the example I gave was /home/user/directory1/directory2/directory3 , and in my example command, everything in directory1 is copied (recurses the directories) including directory2 then directory3... which I want to exclude.

Last edited by dchmelik; 02-18-2021 at 03:44 PM.
 
Old 02-18-2021, 10:06 PM   #5
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
You are right, --exclude=directory2/directory3 should work. And you know what - I tried it, and it did work. This is my directory structure on an Odroid SBC running Ubuntu 16:
Code:
$ tree directory1/
directory1/
├── directory2
│   ├── directory3
│   │   └── passwd
│   └── passwd
├── directory2a
│   └── passwd
├── directory2b
│   └── passwd
├── directory2c
│   └── passwd
└── passwd
Notice that I do have a directory3. Let's see if it gets copied. I run the following on a Centos 8 VM:
Code:
# rsync --version
rsync  version 3.1.3  protocol version 31
... stuff omitted ...
# rsync -av --exclude=directory2/directory3 bbausch@192.168.1.16:/tmp/rsynctest/directory1/ target
bbausch@192.168.1.16's password:
receiving incremental file list
./
passwd
directory2/
directory2/passwd
directory2a/
directory2a/passwd
directory2b/
directory2b/passwd
directory2c/
directory2c/passwd
It's not copied. I don't know what happens on your system.

Last edited by berndbausch; 02-18-2021 at 10:14 PM.
 
1 members found this post helpful.
Old 11-04-2021, 09:51 PM   #6
dchmelik
Senior Member
 
Registered: Nov 2008
Location: USA
Distribution: Slackware, FreeBSD, Illumos, NetBSD, DragonflyBSD, Plan9, Inferno, OpenBSD, FreeDOS, HURD
Posts: 1,073

Original Poster
Rep: Reputation: 148Reputation: 148
I got this working with an exclude.txt.
 
Old 11-04-2021, 10:17 PM   #7
HappyTux
Senior Member
 
Registered: Mar 2003
Location: Nova Scotia, Canada
Distribution: Debian AMD64
Posts: 4,170

Rep: Reputation: 244Reputation: 244Reputation: 244
Good to read you got it sorted and thanks for marking it solved.
 
  


Reply



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
Advanced backup over network rsync andrifurious Linux - Newbie 9 09-28-2015 01:59 AM
rsync over ssh VS rsync.d RISKS tripialos Linux - Security 4 02-20-2013 06:22 PM
LXer: Backup with rsync and rsync.net LXer Syndicated Linux News 0 09-14-2010 04:20 PM
Using rsync to backup data. Best way to backup folders? Micro420 Linux - General 2 11-23-2006 01:13 AM
Rsync server vs rsync over ssh humbletech99 Linux - Networking 1 10-18-2006 12:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 10:06 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