{"id":580,"date":"2023-11-02T21:48:05","date_gmt":"2023-11-02T20:48:05","guid":{"rendered":"https:\/\/gilbert.busana.lu\/?p=580"},"modified":"2023-11-02T21:48:05","modified_gmt":"2023-11-02T20:48:05","slug":"syncing-data-from-truenas-to-qnap-using-rsync","status":"publish","type":"post","link":"https:\/\/www.homeserver.lu\/?p=580","title":{"rendered":"Syncing data from TrueNAS to QNAP using rsync"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">I was looking for a solution to backup my data from my main NAS, a TrueNAS core instance, to a QNAP. Although I found a really good tutorial by <em><a href=\"https:\/\/www.youtube.com\/watch?v=PixyYcIDrtg\" data-type=\"link\" data-id=\"https:\/\/www.youtube.com\/watch?v=PixyYcIDrtg\">Raid Owl<\/a><\/em> explaining how to back up from TrueNAS to Synology, I did not find, at the time, one for QNAP. The following tutorial should give you an idea what you need to do to achieve syncing data from TrueNAS to QNAP using <em>rsync<\/em>. Bear in mind, that although <em>rsync<\/em> does copy your data from A to B but it is technically not a backup solution.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Preparing the QNAP<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Create a share<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">On the QNAP, create a location<em> <\/em>where the backups should go. In the <em>Control Panel<\/em>, <em>Privilege: Shared Folders<\/em>, create a shared folder (e.g. <em>TNbackup<\/em>) and set the permissions. I  personally do prefer that no user (besides the <em>rsync<\/em> user) has access to the backup data share, to avoid that it becomes corrupted. So <em>deny<\/em> or<em> read only <\/em>for all other users should do the trick.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Create a user<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create a user that TrueNAS will use to connect to the QNAP. Let&#8217;s say we call it <em>rsync<\/em>. Make sure that the <em>rsync<\/em> user is part of the <em>administrator<\/em> group. This is mandatory for it to access the QNAP via ssh. Give it <em>read\/write<\/em> permissions on the <em>TNbackup<\/em> share.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the <em>Users<\/em> tab of the <em>control panel<\/em>, <em>enable the home folder for all users<\/em> in the <em>advanced settings<\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the <em>Network &amp; File Services<\/em> tab of the <em>Control Panel<\/em>, activate SSH on port 22 and SFTP. You can also set the <em>Access Permissions<\/em> here.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Verify that you can log in to your QNAP using ssh and your newly created user.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>ssh rsync@[QNAP-IP]<\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Prepare the SSH configuration on QNAP<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the terminal session, open the sshd configuration file in the VI editor. Unfortunately NANO is not installed on QNAP.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>sudo vi \/etc\/ssh\/sshd_config<\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Find and uncomment the next two lines deleting the #-sign. Position your cursor at the beginning of the corresponding line and hit the &#8220;i&#8221;-key for insert-mode.<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-file=\"sshd_config\" data-lang=\"Bash\"><code>#PubkeyAuthentication yes\n#AuthorizedKeysFile  .ssh\/authorized_keys<\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">After deleting the two #-signs, hit the Escape-key. Save using &#8220;:w&#8221; followed by the return key and quit using &#8220;:q&#8221;, followed by the return-key.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now navigate to your users home folder:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>cd \/share\/homes\/rsync\/<\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Create the .ssh folder and the authorized-keys (empty) file:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>mkdir .ssh\nchmod 700 .ssh\ntouch .ssh\/authorized_keys<\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">You can check if the file has been created by using this command:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>ls .ssh\/<\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Set the user permissions on the .ssd folder:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>sudo chmod -R 700 .ssh\nsudo chown -R rsync .ssh<\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">You might need to restart the rsync and ssh services on QNAP using the GUI.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Preparing TrueNAS<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Create a home folder for your user, using the <em>Shell<\/em> provided in the GUI:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>cd \/mnt\/[DATASET POOL]\/\nmkdir home\ncd home\nmkdir rsync<\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Create the user using the Accounts\/User tab and add a new one, filling out the following fields:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Full name: &#91;RSYNC to QNAP]\nUsername: rsync\nPassword: &#91;password]\nConfirm password: &#91;password]\nUser ID (auto filled by TrueNAS)\nPrimary Group: rsync\nAuxiliary Groups: &#91;choose one that has access to the fileshares you want to backup]\nHome Directory: \/mnt\/&#91;DATASET POOL]\/home\/rsync<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That&#8217;s it for now. later on, we will fill in the <em>SSH Public Key<\/em>. Save for now.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s go on and create the SSH key on TrueNAS using ssh with the <em>rsync<\/em> user. Make sure that the SSH service is running on TrueNAS (GUI: services tab). When creating the key, you can skip all the prompts with the Return-key.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Log in via SSH to your <strong>TrueNAS<\/strong>:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>ssh rsync@[TrueNAS-IP]\nssh-keygen<\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">To see the generated key, use:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-file=\"id_rsa.pub\" data-lang=\"Bash\"><code>cat .ssh\/id_rsa.pub<\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Copy everything from that file, from <em>ssh-rsa<\/em> to something like <em>truenas-local<\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Go back to the TrueNAS GUI, edit the <em>rsync<\/em> user and paste the string into the <em>SSH Public-Key<\/em> field. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now log in to your<strong> QNAP<\/strong> via SSH:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-file=\"authorized_keys\" data-lang=\"Bash\"><code>ssh rsync@[QNAP-IP]\nvi .ssh\/authorized_keys<\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Hit &#8220;i&#8221; for insert mode. Paste the key in the file. Hit Escape. Write to disk with &#8220;:w&#8221; and quit with &#8220;:q&#8221;.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To test if the connection is working, go back to your<strong> TrueNAS<\/strong> <strong>SSH session<\/strong> and connect to your QNAP:<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-bash\" data-lang=\"Bash\"><code>ssh rsync@[QNAP-IP]<\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">The QNAP will NOT ask for the password as it uses the key that we just generated and shared between the machines (for the user <em>rsync<\/em>). You have to accept the <em>host key fingerprint<\/em> (it will be saved in your <em>known hosts<\/em> file). If you do not accept it, the rsync task will most probably fail.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Create the Rsync task on TrueNAS<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In the TrueNAS GUI, go to the <em>Tasks<\/em> tab, <em>Rsync Tasks<\/em>. Create a new <em>Rsync Task<\/em>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>Source:<\/strong>\nPath: \/mnt\/&#91;DATASET POOL]\/fileshare_on_TrueNAS\nUser: rsync\nDirection: PUSH\nDescription: Backup TrueNAS to QNAP\nSchedule: what ever you like\n\n<strong>Remote:<\/strong>\nRemote Host: &#91;IP OF QNAP]\nRsync Mode: SSH\nRemote SSH Port: 22\nRemote Path: \/share\/&#91;destination fileshare_on_QNAP] <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">I had to untick the compress tickbox for rsync to run. I also decided to untick the <em>delete<\/em> option. This means that if I inadvertently delete a file on my TrueNAS, it will still exist on the QNAP. Don&#8217;t forget to save.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Alternatively to setting the auxiliary group in the TrueNAS user (see above), you can also make sure that the <em>rsync<\/em> user has the correct ACL permissions (read) on the TrueNAS fileshare that you want to sync.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Run the task manually. If it fails, click on the error button and download the error log.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Be reminded that this procedure will syn the TrueNAS folder&#8217;s content to the QNAP, but it is technically not a backup!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was looking for a solution to backup my data from my main NAS, a TrueNAS core instance, to a QNAP. Although I found a really good tutorial by Raid Owl explaining how to back up from TrueNAS to Synology, I did not find, at the time, one for QNAP. The following tutorial should give [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[33],"tags":[],"class_list":["post-580","post","type-post","status-publish","format-standard","hentry","category-nas"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.homeserver.lu\/index.php?rest_route=\/wp\/v2\/posts\/580","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.homeserver.lu\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.homeserver.lu\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.homeserver.lu\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.homeserver.lu\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=580"}],"version-history":[{"count":55,"href":"https:\/\/www.homeserver.lu\/index.php?rest_route=\/wp\/v2\/posts\/580\/revisions"}],"predecessor-version":[{"id":635,"href":"https:\/\/www.homeserver.lu\/index.php?rest_route=\/wp\/v2\/posts\/580\/revisions\/635"}],"wp:attachment":[{"href":"https:\/\/www.homeserver.lu\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=580"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.homeserver.lu\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=580"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.homeserver.lu\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=580"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}