Tutorial details | |
---|---|
Difficulty | Easy (rss) |
Root privileges | Yes |
Requirements | rsync |
Time | 2m |
Rsync Preserve / Copy Hard Links For Rsnapshot Backup Directory
The syntax is as follows to keep track of hard links when using rsync:
rsync -az -H --delete --numeric-ids /path/to/source server2:/path/to/dest/
## OR ##
rsync -az -H --delete --numeric-ids /path/to/source 192.168.1.5:/path/to/dest/
## OR ##
rsync -az -H --delete --progress --numeric-ids /path/to/source 192.168.1.5:/path/to/dest/
Where,
- -a : Archive mode (i.e. recurse into directories, and preserve symlinks, file permissions, file modification times, file group, file owner, device files & special files)
- -z : Compress file data during the transfer
- -H : Preserve hard links (i.e. copy hard links as hard links)
- --delete : Delete extraneous files from the receiving side (ones that aren't on the sending side), but only for the directories that are being synchronized i.e. keep exact replica of your /raid6/rsnapshot directory.
- --numeric-ids : Transfer numeric group and user IDs rather than using user and group names and mapping them at both ends.
- --progress : Show progress during transfer.
Rsync copy hard links
In short type the following command as root user to copy /raid6/rsanpshot to another backup server named backupserver2:
# rsync -az -H --delete --numeric-ids /raid6/rsanpshot backupserver2:/backups/
You can pull backups too from backupsrver2 as follows:
# rsync -az -H --delete --numeric-ids backupserver1:/raid6/rsanpshot /backups/
Smaller size directories can be dumped to usb 2.0/3.0 or eSata external hard drives using the same syntax. First, mount usb hard drive:
# mount /dev/sdXY /mnt/usbdisk
Next, use the rsync command as follows:
# rsync -az -H --delete --numeric-ids /raid6/rsanpshot /mnt/usbdisk/
Preserving and coping hard links with rsync command
We can set rsync speed limit from eating all bandwidth with –bwlimit option:
rsync -v -a --bwlimit=5000 -H --delete --numeric-ids rsnashot-prod user@192.168.2.19:/rsnapshot
The --bwlimit=KBPS option allows you to specify the maximum transfer rate. The RATE value can be suffixed with a string to indicate a size multiplier, and may be a fractional value (e.g. "–bwlimit=2.5m").
Conclusion
You learned how to copy and preserve hard Links when using rsync command on Linux, macOS, FreeBSD or Unix-like systems.
🐧 8 comments so far... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
I see. I think I would also opt for time machine, but I cnnaot get it to work on NFS. As I don’t want to push Time Machine into doing things it’s not supposed, I think it will be better to make my own aolution. Putting in cleanup of old snapshots shouldn’t be to hard either I think.
Thank you very much for your article, it helped me a lot. I have a question because of your rsync options. When I compare the two directory trees with rsync -rvnc –delete local remote, I get several “Skipping non-regular file: ….” errors, should I add also the –links option to rsync?
Paul,
I ‘m thinking you might want to look at the ‘-D’ option.
Here is a reference:
http://www.linux.com/community/blogs/131-business-or-qenterprise/421384
You might also want to look at excluding directories. /proc/ for example.
-me
thank you for your reply, as far as I understand from the referenced article -D is in included in -a (-rlptgoD) so it is already used, /proc/ is not included in the backup.
This helped me.
Thank you :)
I’m copying my rsync backups from a single drive to a new RAID array, and this was exactly what I needed. Thanks for the information!
Is this affected at all by going from one file system to another? I plan on using this to transfer data from ext4 to zfs
Thanks!!!