Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I want to make sure I am using the correct rsync command on Linux. I do not want to run an rsync and end up losing data as I am new to Linux and I have no backup now.

On Linux Mint, I want to backup /home/nasser/ and everything BELOW it to /home/BACKUP/ where I have a backup disk mounted.

Therefore, I'd like to end up with:

/home/nasser/file1
/home/nasser/file2
/home/nasser/A/file1

to

/home/BACKUP/file1
/home/BACKUP/file2
/home/BACKUP/A/file1

This should include all hidden files and directories preserving ownership and permissions. I made sure that /home/BACKUP/ is owned by me (user and group). (I just created it using sudo and changed owner and group and mounted the backup disk at that point).

The command I plan to use is:

rsync -apvr --delete --chmod=ugo=rwX  /home/nasser/  /home/BACKUP/

I will run this with my user account, not as root.

Is the above command correct to do what I want so I end up with duplicate files in all aspects? I plan to use this for regular backups, so I will use this command each time I want to make sure the backup is up to date.

For reference, these are the full steps I have performed to prepare for the backup.

  1. Bought a USB external disk. Come home and plugin into the PC
  2. Ran dmesg and saw [172850.144032] sd 9:0:0:0: >[sdc] [172850.170378] sd 9:0:0:0: >[sdc] Attached SCSI disk
  3. Determined new disk is recognized at /dev/sdc
  4. Deleted existing partition and created new primary partition.

    # sudo fdisk /dev/sdc

    Command (m for help): d
    Selected partition 1

    Command (m for help): n
    Partition type:
    p primary (0 primary, 0 extended, 4 free)
    e extended
    Select (default p): p
    Partition number (1-4, default 1):

    Chose defaults to use the whole disk.

    Command (m for help): w
    ...
    Syncing disks.

  5. Create ext4 filesystem
    # sudo mkfs.ext4 /dev/sdc1
  6. Create mount point
    # sudo mkdir /home/BACKUP
  7. Mount and assign everything to me, only needed to be done once
    # sudo mount -t ext4 /dev/sdc1 /home/BACKUP/
    # sudo chgrp -R nasser /home/BACKUP/
    # sudo chown -R nasser /home/BACKUP/
share|improve this question
    
Why did you choose to use --delete? –  Bernhard Jan 16 '13 at 13:32
    
So that, if the destination, i.e. /home/Backup ends up with a file that no longer exist in /home/nasser/ I want it deleted and not kept there, so that I have exact copy. For example, I could have deleted /home/nasser/test.txt and I want this to be deleted from /home/BACKUP/test.txt as well. –  Nasser Jan 16 '13 at 13:38
    
Ok, fair enough. But I would like to keep the file in my back-up folder, just in case I accidentally delete something in my home-folder. –  Bernhard Jan 16 '13 at 13:55
    
OK, sure, you can do that. I myself prefer to have exact copy of the whole tree in both places. One nice thing in Linux, is that one have many options :) (but remember, that it is meant to be a backup disk. So think what will happen if your main disk go bad, and now you want to use your backup disk, then your backup disk will have old files around that did not exist in your disk that just died, and you have now to worry about cleaning things , etc... any way, you choose what is good for you. –  Nasser Jan 16 '13 at 13:56
1  
Do not trust any advice given here without checking the relevant manuals, thinking it over, and doing some experiments on your own! (This one you can trust. Trust me.) –  vonbrand Jan 21 '13 at 20:08
add comment

1 Answer

up vote 3 down vote accepted

One caveat is consistency. E.g. if you take a backup while Firefox is updating its database(s), they may become corrupt. That includes Firefox's bookmarks. So you might close other running applications before running the backup... More software is using databases nowadays, including the KDE desktop, so it's starting to get a bit awkward.

man rsync tells me that -a already implies -r and -p. I use -a and --delete. I think that should be fine for most purposes.

It looks like your backup will be readable & writeable by any user. After restoring the backup, this might cause problems with some tools. One example would be SSH, which can refuse to function until you fix its configuration to be secure again. So I personally wouldn't use the chmod option.

You might also like rdiff-backup. It's similar to using rsync, except you don't need to specify -a --delete, and "extra reverse diffs are stored in a special subdirectory of [the] target directory, so you can still recover files lost some time ago."

share|improve this answer
    
This is really strange. I just did rsync -av --delete /home/me/ /home/BACKUP/ and ended up with files on /home/BACKUP that all have the same time-stamp which is the time I issues the command above. So the times on the files did not get copied. All files time stamps in the destination indicate these files are created now. Which is not what I want. But according to man, -a includes -t as well. Very strange. I will try again with adding -t as well and see. –  Nasser Jan 17 '13 at 3:29
    
OMG! I know why it did that! I have a mounted disk under /home/me at the mount point /home/me/data and when I do rsync -av --delete /home/me/ /home/BACKUP/, then /home/BACKUP/data/ and everything below it DO NOT get the same time stamps in /home/me/data/, but they all get new time stamps. This is becuase /home/me/data is mounted disk actually, which is where my data is. I need a way to preserve time stamps and everything on these as well when I do the rsync. I will look more into it. –  Nasser Jan 17 '13 at 3:36
    
Ok, I can't find an option in rsync for this. This might be a limitation or a bug as it should not happen. I'll post a separate question on this, I think that will be better than follow more on this using this question. –  Nasser Jan 17 '13 at 4:51
    
I don't think it should happen either! I don't have any idea unfortunately. –  sourcejedi Jan 17 '13 at 13:57
    
well, I posted separate question on this here: unix.stackexchange.com/questions/61586/… and the only reply was basically is that this is how it is supposed to work. Strange. This means I can't use rsync if I have a mounted disk in the source tree and keep time stamps the same as with files that are not on a mounted disk. –  Nasser Jan 17 '13 at 14:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.