Backup Rsync – Rsync Command to Backup Home Tree to Another Disk

backuprsync

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/

Best Answer

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."

Related Question