Transferring Periodic Backups of /mnt/tosh Using Rsync with Hard Link Handling
Backing up data is an essential task for any system administrator. This article will cover how to transfer periodic backups of the /mnt/tosh directory to a remote server using the rsync command, with a focus on handling hard links.
Why use rsync?
Rsync is a powerful and versatile command-line tool that synchronizes files and directories between a local and a remote host or between two remote hosts. It uses a delta-transfer algorithm, which means that it only transfers the differences between the source and destination directories, minimizing the amount of data transferred and reducing the time it takes to complete the backup.
Preparing for the backup
Before starting the backup, make sure that the /mnt/tosh directory exists and contains the data you want to backup. Also, ensure that the remote server has the necessary storage space to hold the backup.
Transferring the backup using rsync
To transfer the backup of /mnt/tosh to the remote server, use the following rsync command:
rsync -avh --progress --delete /mnt/tosh user@remote:/path/to/backup/directoryHere's what each option does:
-a: Archive mode, which preserves symbolic links, permissions, timestamps, and other file attributes.-v: Verbose mode, which displays progress and other information during the transfer.-h: Human-readable mode, which displays file sizes in a human-readable format.--progress: Displays the progress of the transfer.--delete: Deletes files on the destination that do not exist on the source.
Replace user@remote with the username and IP address or hostname of the remote server, and replace /path/to/backup/directory with the path to the directory where you want to store the backup on the remote server.
Handling hard links
The /mnt/tosh directory may contain subdirectories with hard links, such as /mnt/tosh/vorbis. Handling hard links correctly is important to ensure that the backup is consistent and that the hard links are preserved.
To handle hard links correctly, use the --hard-links option:
rsync -avh --progress --delete --hard-links /mnt/tosh user@remote:/path/to/backup/directoryThis option tells rsync to preserve hard links by creating hard links on the destination for files that have the same inode number as files on the source.
Periodic backups
To transfer periodic backups of /mnt/tosh, you can set up a cron job on the local server to run the rsync command at regular intervals. For example, to run the backup every day at 2 AM, add the following line to the crontab file:
0 2 * * * rsync -avh --progress --delete --hard-links /mnt/tosh user@remote:/path/to/backup/directory- Rsync is a powerful and versatile command-line tool for transferring files and directories between a local and a remote host or between two remote hosts.
- To transfer periodic backups of /mnt/tosh to a remote server using rsync, use the
-avh --progress --delete --hard-linksoptions. - To handle hard links correctly, use the
--hard-linksoption. - To run the backup at regular intervals, set up a cron job on the local server.