You are not logged in.

#1 2014-02-18 15:07:11

Arakis
Member
From: Hamminkeln - Germany
Registered: 2013-08-11
Posts: 46
Website

System backup with rsync: Copy directories without files

Hi guys,
i'm using a single rsync command for backup / copying my system. I skip a lot of directories, because they are big or aren't needed to copy an existing arch installation. I found out, that the content of var/log and var/spool should not deleted entirely, becuase sub directories have to be there with specified permission/ownerships.

This is my current backup-script:

#!/bin/sh

SRC="/nfs"
DST="/mnt"

sudo rsync -aAXv --delete $SRC/* $DST --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/var/log/*,/media/*,/lost+found,/home/*/.gvfs,/data/,/backup/,/home/*,/root/*,/var/abs/local/yaourtbuild/*,/var/cache/pacman/pkg/*,/scripts/*,/var/spool/cups/*,/var/spool/cups-pdf/*,/var/tmp/*,/etc/ppp/peers/*}

I read the manpage of rsync, but i did not found out, how to copy a directory with all subdirectories, but exlude all files in it.

By the way: i hope the options "aAXv" are perfect - i never had problem with them in the history. But one question: What is when a fileowner does not exists on the target machine, will it mapped to "nobody"? For normal users, this does not matter, becuase i skip the entiere /home dir, but in /etc could some files owned by service-users, that does not exists on the target maschine.

Greetings,
Sebastian

Offline

#2 2014-02-19 10:55:25

Rexilion
Member
Registered: 2013-12-23
Posts: 784

Re: System backup with rsync: Copy directories without files

You could use the '-x' option to use one filesystem. So you can drop anything related to dev proc sys and all other fs'es with a tmpfs mount.

You could use the find command with the print0 switch to more exactly define what you (don't) want.

On most filesystems, users are stored as numerical id's. Unknown numerical id's will just show the number in the field of owner/group. Other users except for root will be able to access them based on the world bit.


fs/super.c : "Self-destruct in 5 seconds.  Have a nice day...\n",

Offline

#3 2014-02-19 13:52:39

brain0
Developer
From: Aachen - Germany
Registered: 2005-01-03
Posts: 1,382

Re: System backup with rsync: Copy directories without files

I use the following snippet in file a passed via --include-from=

+ /var/**/
+ /var/lock
+ /var/run
+ /var/mail
+ /var/lib/pacman/**
+ /var/lib/texmf/**
- /var/**

It basically says: Copy all directories in /var, copy /var/{lock,run,mail} (which are all symlinks), copy /var/lib/{pacman,texmf} completely, skip all files in /var. The logic with --exclude is kind of reversed, but I hope this helps.

Last edited by brain0 (2014-02-19 13:53:12)

Offline

#4 2014-02-19 15:31:01

Arakis
Member
From: Hamminkeln - Germany
Registered: 2013-08-11
Posts: 46
Website

Re: System backup with rsync: Copy directories without files

Hello Rexilion,
the tip with find and print0 was greate and works.

The i know about -x option, but it do not work in my case (i don't know why), it will copy all content of /dev (it should not).

In the moment, i'm using this script to copy my arch installation:

#!/bin/sh

SRC="/mnt3"
DST="/mnt"

cd $SRC # important for relative find command

sudo rsync -aAXvz --delete $SRC/* $DST --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/var/log/*,/lost+found,/home/*/.gvfs,/data/,/backup/,/home/*,/root/*,/var/abs/local/yaourtbuild/*,/var/cache/pacman/pkg/*,/scripts/*,/var/spool/*,/var/tmp/*,/etc/ppp/peers/*} --progress
find var/log            -type d -print0 | rsync -av --files-from=- --from0 $SRC $DST
find var/spool          -type d -print0 | rsync -av --files-from=- --from0 $SRC $DST

Are there more directories, that could contain sensitive data, that should not copied to another computer (for example, when my arch installation should copied to a "foreign" computer)?

/etc/passwd should not be a problem, the passowrds are hashed. And in /etc/ssh, i have no important private keys - ok, maybe i'm wrong, maybe i should regenerate them via "ssh-keygen -A"

Any other ideas, what should be keeped in mind, when copy an existing arch installation to another "foreign" machine?

Offline

#5 2014-02-20 07:28:10

Rexilion
Member
Registered: 2013-12-23
Posts: 784

Re: System backup with rsync: Copy directories without files

About /dev still being copied: There could still be static files under /dev on your regular root partition. In my case it's empty. They are harmless. Yet still, one could use '-x' and explicitly exclude /dev as you are doing now.

About the rest of your question: SSH local keys, TOR data, CUPS printer spool. You should check all data under '/var'.

Last edited by Rexilion (2014-02-20 07:29:18)


fs/super.c : "Self-destruct in 5 seconds.  Have a nice day...\n",

Offline

Board footer

Powered by FluxBB