{"id":475,"date":"2022-04-20T19:52:04","date_gmt":"2022-04-20T19:52:04","guid":{"rendered":"https:\/\/www.millermattson.com\/dave\/?p=475"},"modified":"2022-08-27T16:50:03","modified_gmt":"2022-08-27T16:50:03","slug":"475","status":"publish","type":"post","link":"https:\/\/millermattson.com\/dave\/?p=475","title":{"rendered":"Linux backups on a Synology NAS"},"content":{"rendered":"\n<!DOCTYPE html>\n<html>\n<head>\n\n<meta http-equiv=\"Content-type\" content=\"text\/html;charset=UTF-8\">\n\n<style>\n\nbody {\n\tfont-family: var(--vscode-markdown-font-family, -apple-system, BlinkMacSystemFont, \"Segoe WPC\", \"Segoe UI\", \"Ubuntu\", \"Droid Sans\", sans-serif);\n\tfont-size: var(--vscode-markdown-font-size, 14px);\n\tpadding: 0 26px;\n\tline-height: var(--vscode-markdown-line-height, 22px);\n\tword-wrap: break-word;\n}\n\n#code-csp-warning {\n\tposition: fixed;\n\ttop: 0;\n\tright: 0;\n\tcolor: white;\n\tmargin: 16px;\n\ttext-align: center;\n\tfont-size: 12px;\n\tfont-family: sans-serif;\n\tbackground-color:#444444;\n\tcursor: pointer;\n\tpadding: 6px;\n\tbox-shadow: 1px 1px 1px rgba(0,0,0,.25);\n}\n\n#code-csp-warning:hover {\n\ttext-decoration: none;\n\tbackground-color:#007acc;\n\tbox-shadow: 2px 2px 2px rgba(0,0,0,.25);\n}\n\nbody.scrollBeyondLastLine {\n\tmargin-bottom: calc(100vh - 22px);\n}\n\nbody.showEditorSelection .code-line {\n\tposition: relative;\n}\n\nbody.showEditorSelection .code-active-line:before,\nbody.showEditorSelection .code-line:hover:before {\n\tcontent: \"\";\n\tdisplay: block;\n\tposition: absolute;\n\ttop: 0;\n\tleft: -12px;\n\theight: 100%;\n}\n\nbody.showEditorSelection li.code-active-line:before,\nbody.showEditorSelection li.code-line:hover:before {\n\tleft: -30px;\n}\n\n\n\nimg {\n\tmax-width: 100%;\n\tmax-height: 100%;\n}\n\na {\n\ttext-decoration: none;\n}\n\na:hover {\n\ttext-decoration: underline;\n}\n\na:focus,\ninput:focus,\nselect:focus,\ntextarea:focus {\n\toutline: 1px solid -webkit-focus-ring-color;\n\toutline-offset: -1px;\n}\n\nhr {\n\tborder: 0;\n\theight: 2px;\n\tborder-bottom: 2px solid;\n}\n\nh1 {\n\tpadding-bottom: 0.3em;\n\tline-height: 1.2;\n\tborder-bottom-width: 1px;\n\tborder-bottom-style: solid;\n}\n\nh1, h2, h3 {\n    padding-top: 1em;\n\tfont-weight: normal;\n}\n\ntable {\n\tborder-collapse: collapse;\n}\n\ntable > thead > tr > th {\n\ttext-align: left;\n\tborder-bottom: 1px solid;\n}\n\ntable > thead > tr > th,\ntable > thead > tr > td,\ntable > tbody > tr > th,\ntable > tbody > tr > td {\n\tpadding: 5px 10px;\n}\n\ntable > tbody > tr + tr > td {\n\tborder-top: 1px solid;\n}\n\nblockquote {\n\tmargin: 0 7px 0 5px;\n\tpadding: 0 16px 0 10px;\n\tborder-left-width: 5px;\n\tborder-left-style: solid;\n}\n\ncode {\n\tfont-family: Menlo, Monaco, Consolas, \"Droid Sans Mono\", \"Courier New\", monospace, \"Droid Sans Fallback\";\n\tfont-size: 1em;\n\tline-height: 1.357em;\n}\n\nbody.wordWrap pre {\n\twhite-space: pre-wrap;\n}\n\npre:not(.hljs),\npre.hljs code > div {\n\tpadding: 4px;\n\tborder-radius: 3px;\n\toverflow: auto;\n}\n\npre code {\n\tcolor: var(--vscode-editor-foreground);\n\ttab-size: 4;\n}\n\n\/** Theming *\/\n\n\n\n<\/style>\n\n<style>\n\n.hljs {\n\tdisplay: block;\n\toverflow-x: auto;\n\tcolor: #4d4d4c;\n\tpadding: 0.5em;\n}\n\n\n<\/style>\n\n<style>\n\/*\n * Markdown PDF CSS\n *\/\n\n body {\n\tfont-family: -apple-system, BlinkMacSystemFont, \"Segoe WPC\", \"Segoe UI\", \"Ubuntu\", \"Droid Sans\", sans-serif, \"Meiryo\";\n\tpadding: 0 12px;\n}\n\npre {\n\tbackground-color: #f8f8f8;\n\tborder: 1px solid #cccccc;\n\tborder-radius: 3px;\n\toverflow-x: auto;\n\twhite-space: pre-wrap;\n\toverflow-wrap: break-word;\n}\n\npre:not(.hljs) {\n\tpadding: 23px;\n\tline-height: 19px;\n}\n\nblockquote {\n\tbackground: rgba(127, 127, 127, 0.1);\n\tborder-color: rgba(0, 122, 204, 0.5);\n}\n\n.emoji {\n\theight: 1.4em;\n}\n\ncode {\n\tfont-size: 14px;\n\tline-height: 19px;\n}\n\np {\n    padding-top: 0.0em;\n    padding-bottom: 0.0em;\n}\n\nli p {\n    margin: 0em 0.0em;\n}\n\n.shad {\n    font-style: italic;\n}\n\n\/* for inline code *\/\n:not(pre):not(.hljs) > code {\n\tcolor: #C9AE75; \/* Change the old color so it seems less like an error *\/\n\tfont-size: inherit;\n}\n\n\/* Page Break : use <div class=\"page\"\/> to insert page break\n-------------------------------------------------------- *\/\n.page {\n\tpage-break-after: always;\n}\n\n<\/style>\n\n\n<\/head>\n<body>\n  <script>\n    mermaid.initialize({\n      startOnLoad: true,\n      theme: document.body.classList.contains('vscode-dark') || document.body.classList.contains('vscode-high-contrast')\n          ? 'dark'\n          : 'default'\n    });\n  <\/script>\n\n<p>The Synology NAS products work well for backing up or sharing media files and documents in an informal home environment. However, a Synology NAS is not well suited as a general backup device for a Linux computer.<\/p>\n<p>The problems below can be overcome by archving your Linux files with tar or an equivalent archive manager, then copying the tarballs to the Synology NAS. But that can be inconvenient. You might be tempted to use the Synology NAS as an extension drive and simply copy files to the NAS for backup. However, therein lies four gotchas for the Linux user which we&#8217;ll discuss below:<\/p>\n<ul>\n<li>\n<p>File permissions<\/p>\n<\/li>\n<li>\n<p>File ownership<\/p>\n<\/li>\n<li>\n<p>Case insensitive filesystem<\/p>\n<\/li>\n<li>\n<p>Symlinks<\/p>\n<\/li>\n<\/ul>\n<h2 id=\"file-permissions\">File permissions<\/h2>\n<p>Suppose we start with a sensitive file on the Linux computer with permissions set so that only the owner can access the file:<\/p>\n<pre class=\"hljs\"><code><div>-rw------- 1 dm dm 4 Apr 20 11:06 junk\n<\/div><\/code><\/pre>\n<p>Suppose we use rsync -a to copy the file to the NAS and then copy it back like this:<\/p>\n<pre class=\"hljs\"><code><div>rsync -av .\/junk dm@192.168.1.111:\/volume1\/drm\nrsync -av dm@192.168.1.111:\/volume1\/drm\/junk .\n<\/div><\/code><\/pre>\n<p>The permissions are retained, great. But if we mount the NAS drive on our Linux computer with Samba, the permissions allow anyone to read it:<\/p>\n<pre class=\"hljs\"><code><div>-r--r--r-- 1 dm dm 1740013 Apr 20 10:59  junk\n<\/div><\/code><\/pre>\n<p class=\"shad\">To preserve sensitive file permissions when backing up and restoring files, you must copy and restore the files using rsync -a directly to and from the NAS and never allow anyone else to mount the NAS filesystem.<\/p>\n<h2 id=\"file-ownership\">File ownership<\/h2>\n<p>Suppose your Linux computer has a file owned by user dm and group www-data:<\/p>\n<pre class=\"hljs\"><code><div>-rw-rw-r-- 1 dm www-data 0 Apr 20 11:14 junk\n<\/div><\/code><\/pre>\n<p>Let&#8217;s use rsync -a to copy it to the NAS and back:<\/p>\n<pre class=\"hljs\"><code><div>rsync -av .\/junk dm@192.168.1.111:\/volume1\/drm\nrsync -av dm@192.168.1.111:\/volume1\/drm\/junk .\n<\/div><\/code><\/pre>\n<p>Now its group ownership on the Linux computer has been lost:<\/p>\n<pre class=\"hljs\"><code><div>-rw-rw-r-- 1 dm dm 0 Apr 20 11:14 junk\n<\/div><\/code><\/pre>\n<p>And if we look at the file by mounting the NAS directory on our Linux computer, the write permissions for group has been lost:<\/p>\n<pre class=\"hljs\"><code><div>-rw-r--r-- 1 dm dm 0 Apr 20 11:23 junk\n<\/div><\/code><\/pre>\n<p class=\"shad\">To backup and restore ownership and permissions for group and other, such as for files used by a web server, archive the files with tar or an other archive manager that preserves ownership and permissions.<\/p>\n<p>Backing up your files in tarballs means that you cannot use the NAS&#8217;s Btrfs filesystem to make snapshots of backups. You can make incremental tarball backups, but restoring them means having to restore multiple tar files on top of each other.<\/p>\n<h2 id=\"case-insensitive-filesystem\">Case insensitive filesystem<\/h2>\n<p>On a Linux filesystem, filename case is significant. For example, you could distinguish between a full-size image and a thumbnail by naming them with upper and lower case:<\/p>\n<pre class=\"hljs\"><code><div>dm@linuxbox:\/tmp$ ls -l junkdir\n-rw-rw-r-- 1 dm dm  335160 Apr 20 11:34 junk.jpg\n-rw-rw-r-- 1 dm dm 7654088 Apr 20 11:34 junk.JPG\n<\/div><\/code><\/pre>\n<p>In many Linux distributions, some directories contain variations of filenames that differ only in upper or lower case.<\/p>\n<p>If we use rsync -a to copy such files to the NAS, the filename casing is preserved and all the files are copied. But let&#8217;s use rsync -a to copy our two test files to a NAS directory mounted on our Linux computer:<\/p>\n<pre class=\"hljs\"><code><div>dm@linuxbox:\/tmp$ rsync -av .\/junkdir\/ \/home\/dm\/mnt\/nasdir\/junkdir\/\n<\/div><\/code><\/pre>\n<p>Now only one file got copied, with the name of one of the files and the contents of the other file:<\/p>\n<pre class=\"hljs\"><code><div>dm@linuxbox:~\/mnt\/nasdir$ ls -l ~\/mnt\/nasdir\/junkdir\/\n-rw-r--r-- 1 dm dm 335160 Apr 20 11:34 junk.JPG\n<\/div><\/code><\/pre>\n<p>Rsync to a mounted NAS drive is case insensitive, so the first file got copied, then the second file that was copied overwrote the first file but the filename was unchanged.<\/p>\n<p class=\"shad\">To avoid losing files that differ in name casing, rsync directly to and from the NAS and not through a mounted NAS directory.<\/p>\n<h2 id=\"symlinks\">Symlinks<\/h2>\n<p>Symbolic links cannot be copied from a Linux computer to the Synology NAS. The Linux operating system and many applications use symlinks and will no longer fully function if backed up to a Synology NAS and then restored without the symlinks.<\/p>\n<p class=\"shad\">To backup and restore operating system files and applications, use tar or another archive manager that preserves symlinks.<\/p>\n\n<\/body>\n<\/html>\n","protected":false},"excerpt":{"rendered":"<p>The Synology NAS products work well for backing up or sharing media files and documents in an informal home environment. However, a Synology NAS is not well suited as a general backup device for a Linux computer. The problems below can be overcome by archving your Linux files with tar or an equivalent archive manager, [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-475","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/millermattson.com\/dave\/index.php?rest_route=\/wp\/v2\/posts\/475","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/millermattson.com\/dave\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/millermattson.com\/dave\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/millermattson.com\/dave\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/millermattson.com\/dave\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=475"}],"version-history":[{"count":3,"href":"https:\/\/millermattson.com\/dave\/index.php?rest_route=\/wp\/v2\/posts\/475\/revisions"}],"predecessor-version":[{"id":479,"href":"https:\/\/millermattson.com\/dave\/index.php?rest_route=\/wp\/v2\/posts\/475\/revisions\/479"}],"wp:attachment":[{"href":"https:\/\/millermattson.com\/dave\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=475"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/millermattson.com\/dave\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=475"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/millermattson.com\/dave\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=475"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}