Friday, September 8, 2023

rsync - Syntax for Copying Data Between Two QNAP NAS Devices

 


Intro:

A few weeks ago I had a QNAP box shit the bed. One of the drives in the 8 disk array had a bad sector while another drive was throwing unrecoverable read errors. I needed an immediate way to copy the data to a new QNAP NAS since I could not get access to the SMB shares. When a disk or two fails based on the RAID level, the array falls into what QNAP calls, "Read-Only" mode. The array cannot be written to at this point which poses a problem if this is the first pool and your applications are installed here.

None of the GUI applications like "Hybrid Backup Sync 3" or "File Station" were working. Rsync is now the only option. Thankfully "Hybrid Backup Sync 3" was installed on the source box prior to the drives failing or I don't think the rsync service would have been active (there's a toggle to turn it on in HBS3). There is a way to stop and start all services but not individual ones on these boxes from what I can tell. It really wouldn't have mattered in this case since the applications cannot write temporary data to the pool since it's in a read-only state.

Rsync on QNAP devices seems to be a customized version. They're running "version 3.0.7 protocol version 30" dated 2009. According to rsync's wiki, the current stable version at the time of writing (09/08/23) is 3.2.7. So technically we're using a really outdated copy which may induce errors.

I have a 10Gbps fibre link between these two QNAP boxes using (2) Silicom Intel 82599ES Dual-Port SFP+ cards (there's an interesting article coming about modifying the 82599 EEPROM of Intel based X520 cards to use any brand fibre transceiver, not just Intel branded ones) but because the source system is in "Read-Only" mode the copy operation is being slowed to an average of 150-250 MB/s. There's also other issues with one of the new disks appearing offline which may contribute to this however focusing on getting the data off this box asap is the priority.

So far I've copied about 70 TB over this link at those speeds. Painfully slow. At one point while reading and failing on a file, the read speed dropped to around 30 MB/s. Obviously there's an issue on the disk's surface in that area and that drive is destined for the scrap pile since it's out of warranty.

With the exception of that one small file which I had a backup for, everything else copied without incident taking approximately a week at those speeds.


rsync Syntax:

Here's the syntax I used to copy data from a TVS-871 (QTS) to a new TVS-h874 (QuTS hero):

rsync --progress --protect-args -avhro "/share/CACHEDEV1_DATA/<INSERT FOLDER HERE>/" user@172.16.0.3:"/share/ZFS19_DATA/<DESTINATION FOLDER>/"
Dry-Run:

To do a dry-run without copying anything, add an "n" to the beginning or end of "-avhro". This is good for determining the folder size prior to the actual copy operation.

Excluding Folders:

If you need to exclude folders create a file named, "pattern.txt" and add the excluded folders:
  1. "vi pattern.txt"
  2. Press "Insert" key to begin editing file.
  3. Add one folder name per line i.e.,
    • @Recycle
    • .@__thumb
    • .streams
  4. ":wq!" to save and exit.
    1. ":q!" to exit without saving.
Run the following command to invoke "pattern.txt" along with rsync.

rsync --progress --protect-args -avhro --exclude-from="/root/pattern.txt" "/share/CACHEDEV1_DATA/<INSERT FOLDER HERE>/" bob@172.16.0.3:"/share/ZFS19_DATA/<DESTINATION FOLDER>/"

Explanation of Command Syntax:

    rsyncThis is the command itself, used for synchronizing files and directories between two locations.

    --progressThis option displays the progress of the file transfer, showing information like the number of files transferred and the amount of data transferred.

    --protect-argsThis option ensures that the arguments passed to rsync are not parsed by a remote shell. It helps prevent issues with special characters or spaces in file or folder names.

    -a = Archive mode, which is a comprehensive option that includes recursion, preserves symbolic links, permissions, timestamps, owner, and group information.

    -v = Verbose mode, which displays more information about the files being transferred.

    -hHuman-readable output, making the progress and transfer rates more easily understood by humans.

    -rRecurse into directories, allowing rsync to copy directories and their contents recursively.

    -oPreserve owner information.

    -nThis is the "dry-run" or "simulate" option. It tells rsync to perform a trial run without actually making any changes. It's useful for testing the command before running it for real. Remove this flag when running command for real.

    --exclude-from="/root/pattern.txt" = This seems to be custom build of rsync for QNAP. See here for more information (https://andreas.scherbaum.la/blog/archives/1135-QNAP-exclude-files-and-directories-from-rsync.html) It works by matching folder names located in "pattern.txt" and excludes them from the file copy operation. This is useful to exclude copying temporary files or redundant files.

    "/share/CACHEDEV1_DATA/<INSERT FOLDER HERE>/" = This is the source path under QTS (This folder may be different for your NAS), where you should replace <INSERT FOLDER HERE> with the actual name of the folder you want to synchronize from. The quotes are used is the folder name has spaces in it. *Make sure trailing slash exists or copy will fail.

    bob@172.16.0.3:"/share/ZFS19_DATA/<DESTINATION FOLDER>/" = This is the destination path under QuTS hero on the second data pool. This folder may be different for your NAS. It specifies the username (bob) and the IP address (172.16.0.3) of the remote machine where you want to synchronize files. Replace <DESTINATION FOLDER> with the actual name of the destination folder on the remote machine. The quotes are used is the folder name has spaces in it. *Make sure trailing slash exists or copy will fail.


Final Thoughts:

In normal operation rsync through "Hybrid Backup Sync 3" shouldn't required the knowledge of any command line jargon. It's fairly easy to use and as long as you setup "Storage Spaces" in "HBS3" you should be good to go.

I'm hopeful for an updated version of rsync on QTS or QuTS hero, although I'm not really counting on it, given that they're currently using a version which is 14 years old—v3.0.7, released on December 31st, 2009.



๐Ÿ‘ฝ

No comments: