{"id":5800,"date":"2018-10-16T23:24:22","date_gmt":"2018-10-16T21:24:22","guid":{"rendered":"https:\/\/michlstechblog.info\/blog\/?p=5800"},"modified":"2018-10-19T13:17:24","modified_gmt":"2018-10-19T11:17:24","slug":"samba-setup-for-windows-previous-versions-support","status":"publish","type":"post","link":"https:\/\/michlstechblog.info\/blog\/samba-setup-for-windows-previous-versions-support\/","title":{"rendered":"Samba: Setup for Windows Previous Versions Support"},"content":{"rendered":"<div class=\"twoclick_social_bookmarks_post_5800 social_share_privacy clearfix 1.6.4 locale-en_US sprite-en_US\"><\/div><div class=\"twoclick-js\"><script type=\"text\/javascript\">\/* <![CDATA[ *\/\njQuery(document).ready(function($){if($('.twoclick_social_bookmarks_post_5800')){$('.twoclick_social_bookmarks_post_5800').socialSharePrivacy({\"services\":{\"flattr\":{\"uid\":\"Michl\",\"status\":\"on\",\"the_title\":\"Samba%3A%20Setup%20for%20Windows%20Previous%20Versions%20Support\",\"the_excerpt\":\"%0D%0A%0D%0A%0D%0AHi%2C%0D%0A%0D%0Athis%20post%20describes%20how%20to%20setup%20samba%20to%20provide%20filesystem%20snapshots%20to%20Windows%20in%20its%20%22Previous%20Versions%22%20tab.%0D%0A%0D%0AInstall%20your%20prefered%20Linux%20Distribution.%20In%20this%20tutorial%20debian%209%20stretch.%0D%0A%20%28more%26hellip%3B%29\",\"txt_info\":\"2 clicks for more data protection:\\r\\n\\r\\nOnly when you click here, the button will be come active and you can send your recommendation to Flattr. When activating, data are transmitted to third parties. \",\"perma_option\":\"off\"}},\"txt_help\":\"When you activate these fields by clicking, information to Flattr may be transferred abroad, and probably may also stored there.\",\"settings_perma\":\"Enable permanently and accept data transmission. \",\"info_link\":\"http:\\\/\\\/www.heise.de\\\/ct\\\/artikel\\\/2-Klicks-fuer-mehr-Datenschutz-1333879.html\",\"uri\":\"https:\\\/\\\/michlstechblog.info\\\/blog\\\/samba-setup-for-windows-previous-versions-support\\\/\",\"post_id\":5800,\"post_title_referrer_track\":\"Samba%3A+Setup+for+Windows+Previous+Versions+Support\",\"display_infobox\":\"on\"});}});\n\/* ]]> *\/<\/script><\/div><p><!-- https:\/\/forum.openmediavault.org\/index.php\/Thread\/7331-GUIDE-Windows-Previous-Versions-and-Samba-Btrfs-Atomic-COW-Volume-Shadow-Copy\/ https:\/\/www.samba.org\/samba\/docs\/current\/man-html\/vfs_shadow_copy2.8.html https:\/\/wiki.gentoo.org\/wiki\/Samba_shadow_copies https:\/\/wiki.gentoo.org\/wiki\/Btrfs_snapshots https:\/\/forum.openmediavault.org\/index.php\/Thread\/7332-Windows-Previous-Versions-and-Samba\/ --><\/p>\n<p><!-- ACL https:\/\/wiki.samba.org\/index.php\/Setting_up_a_Share_Using_Windows_ACLs --><br \/>\nHi,<\/p>\n<p>this post describes how to setup samba to provide filesystem snapshots to Windows in its &#8220;Previous Versions&#8221; tab.<\/p>\n<p>Install your prefered Linux Distribution. In this tutorial debian 9 stretch.<br \/>\n<!--more--><br \/>\nLet us assume <strong>\/dev\/sda<\/strong> is the disk for the <strong>operating system<\/strong> and <strong>\/dev\/sdb<\/strong> the <strong>disk<\/strong> for <strong>data<\/strong>. 2 Types of shares should exist. Home shares and project shares. All homes are inclued if a snapshot is triggered (Should demonstrate multiple shares in one subvolume). While each project can have its own snapshots (One share per subvolume).<\/p>\n<p>The previous version feature requieres a filesystem with snapshot support. Linux just support one natively: btrfs. Install btrfs tools\/support and gdisk<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev ~ # apt-get install btrfs-progs gdisk samba attr\r\n<\/pre>\n<p>Prepare your disk. Partition 1 (\/dev\/sdb1) should hold the homes (mount point \/mnt-home) and partition 2 the projects (mount point \/mnt-projects). create and format the partitions. I use gpart for partitioning. It creates a GPT based layout but if you have a disk &lt;2TB a MBR layout is also possible.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev ~ # gdisk \/dev\/sdb\r\nCommand (? for help): n\r\nPartition number (1-128, default 1):\r\nFirst sector (34-16777182, default = 2048) or {+-}size{KMGTP}:\r\nLast sector (2048-16777182, default = 16777182) or {+-}size{KMGTP}: 1600G\r\nPartition number (1-128, default 2):\r\n...\r\nroot@debdev ~ # mkfs.btrfs \/dev\/sdb1\r\nroot@debdev ~ # mkfs.btrfs \/dev\/sdb2\r\n<\/pre>\n<p>Create Mountpoints<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev ~ # mkdir \/mnt-home\r\nroot@debdev ~ # mkdir \/mnt-projects\r\n<\/pre>\n<p>Mount the partitions at boot time. Append the following lines to \/etc\/fstab<br \/>\n<code><br \/>\n\/dev\/sdb1 \/mnt-home     btrfs defaults,noatime,rw 0 0<br \/>\n\/dev\/sdb2 \/mnt-projects btrfs defaults,noatime,rw 0 0<br \/>\n<\/code><br \/>\nReboot and check if the partitions are mounted correctly<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev ~ # mount | grep sdb\r\n\/dev\/sdb1 on \/mnt-home type btrfs (rw,noatime,space_cache,subvolid=5,subvol=\/)\r\n\/dev\/sdb2 on \/mnt-projects type btrfs (rw,noatime,space_cache,subvolid=5,subvol=\/)\r\n<\/pre>\n<p>Create subvolumes. subvolumes are the basis for snapshots. The root folders of the partitions are already subvolumes but we need additional ones for the snapshots.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev ~ # btrfs subvolume create \/mnt-home\/homes \r\nroot@debdev ~ # btrfs subvolume create \/mnt-home\/.snapshots\r\nroot@debdev ~ # btrfs subvolume create \/mnt-projects\/projects \r\nroot@debdev ~ # btrfs subvolume create \/mnt-projects\/.snapshots\r\n<\/pre>\n<p>Additionally I will here describe all steps (for a standalone windows workgroup server) including the creation of user and groups. 2 Users which its own Windows Samba Share and access to one project.<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev ~ # groupadd project1\r\nroot@debdev ~ # useradd  -s \/bin\/false -G users,project1 user1\r\nroot@debdev ~ # useradd  -s \/bin\/false -G users,project1 user2\r\n<\/pre>\n<p>Add Windows\/Samba Users and passwords <\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev ~ # smbpasswd -a user1\r\nroot@debdev ~ # smbpasswd -a user2\r\n<\/pre>\n<p>Create folders and set permissions<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev ~ # mkdir \/mnt-home\/homes\/user1\r\nroot@debdev ~ # chown user1:user1 \/mnt-home\/homes\/user1\r\nroot@debdev ~ # chmod 770 \/mnt-home\/homes\/user1\r\nroot@debdev ~ # mkdir \/mnt-home\/homes\/user2\r\nroot@debdev ~ # chown user2:user2 \/mnt-home\/homes\/user2\r\nroot@debdev ~ # chmod 770 \/mnt-home\/homes\/user2\r\nroot@debdev ~ # btrfs subvolume create \/mnt-projects\/projects\/project1\r\nroot@debdev ~ # btrfs subvolume create \/mnt-projects\/.snapshots\/project1\r\nroot@debdev ~ # chown root:project1 \/mnt-projects\/projects\/project1\r\nroot@debdev ~ # chmod 770 \/mnt-projects\/projects\/project1\r\n<\/pre>\n<p>Move old config<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev ~ # mv \/etc\/samba\/smb.conf \/etc\/samba\/smb.conf.org\r\n<\/pre>\n<p>Samba example config <strong>\/etc\/samba\/smb.conf<\/strong><\/p>\n<pre><code>\r\n[global]\r\n        workgroup = YOURWORKGROUP\r\n        netbios name = yourserver\r\n        server string = Samba Server\r\n        # interfaces = 127.0.0.1, eth0\r\n        # bind interfaces only = Yes\r\n        security = USER\r\n        map to guest = Bad User\r\n        os level = 1\r\n        preferred master = No\r\n        local master = No\r\n        domain master = No\r\n        guest account = nobody\r\n        unix charset = UTF8\r\n        directory mask = 0770\r\n        create mask = 0640\r\n        # inherit permissions = yes\r\n        inherit owner = yes\r\n        client ntlmv2 auth = yes\r\n        client lanman auth = no\r\n        client plaintext auth = no\r\n        # Only ntlmv2\r\n        ntlm auth = yes\r\n        lanman auth = no\r\n        encrypt passwords = yes\r\n        access based share enum = yes\r\n        server signing = auto\r\n        client signing = auto\r\n        vfs objects = acl_xattr\r\n        map acl inherit = yes\r\n        store dos attributes = yes\r\n\r\n[project1$]\r\n        path = \/mnt-projects\/projects\/project1\r\n        # Group project1\r\n        valid users = @project1\r\n        # admin users = root, michael\r\n        write list = @project1\r\n        force group = project1\r\n        read only = No\r\n        guest ok = no\r\n        vfs objects = shadow_copy2\r\n        # <span style=\"color: #800080;\">\/mnt-projects\/.snapshots\/projects<\/span>\/@GMT_2018.10.16-21.31.48\r\n        # <span style=\"color: #ff9900;\">shadow:basedir<\/span> =&gt; subvolume\r\n        <span style=\"color: #ff9900;\">shadow:basedir<\/span> = \/mnt-projects\/projects\/project1\r\n        <span style=\"color: #800080;\">shadow:snapdir<\/span> = \/mnt-projects\/.snapshots\/project1\r\n        shadow:format = @GMT_%Y.%m.%d-%H.%M.%S\r\n        shadow:sort = desc\r\n        shadow:localtime = no\r\n        directory mask = 0770\r\n        create mask = 0660\r\n\r\n[user1$]\r\n        comment = Home User1\r\n        browsable = no\r\n        path = \/mnt-home\/homes\/user1\r\n        writable = yes\r\n        write list = user1\r\n        guest ok = no\r\n        vfs objects = shadow_copy2\r\n        # \/mnt-home\/.snapshots\/@GMT_2018.10.16-21.31.48\/user1\r\n        shadow:basedir = \/mnt-home\/homes\r\n        shadow:share_root = user1\r\n        shadow:snapdir = \/mnt-home\/.snapshots\r\n        shadow:format = @GMT_%Y.%m.%d-%H.%M.%S\r\n        shadow:sort = desc\r\n        shadow:localtime = no\r\n\r\n[user2$]\r\n        comment = Home User2\r\n        browsable = no\r\n        path = \/mnt-home\/homes\/user2\r\n        writable = yes\r\n        write list = user2\r\n        guest ok = no\r\n        vfs objects = shadow_copy2\r\n        # <span style=\"color: #ff9900;\">\/mnt-home\/.snapshots<\/span>\/@GMT_2018.10.16-21.31.48\/<span style=\"color: #00ccff;\">user2\r\n        <\/span>#<span style=\"color: #00ccff;\"> <span style=\"color: #800080;\">shadow:basedir =&gt; subvolume<\/span><\/span>\r\n        <span style=\"color: #800080;\">shadow:basedir<\/span> = \/mnt-home\/homes\r\n        <span style=\"color: #00ccff;\">shadow:share_root<\/span> = user2\r\n        <span style=\"color: #ff9900;\">shadow:snapdir<\/span> = \/mnt-home\/.snapshots\r\n        shadow:format = @GMT_%Y.%m.%d-%H.%M.%S\r\n        shadow:sort = desc\r\n        shadow:localtime = no\r\n<\/code><\/pre>\n<p>Ok, time to start samba<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev ~ # systemctl enable smbd.service\r\nroot@debdev ~ # systemctl start smbd.service\r\n<\/pre>\n<p>Try to connect to the shares and copy some data <\/p>\n<p>Creating snapshots. Of all homes:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev ~ # btrfs subvolume snapshot -r \/mnt-home\/homes \/mnt-home\/.snapshots\/@GMT_`date -u +%Y.%m.%d-%H.%M.%S`\r\n<\/pre>\n<p>Note: <strong>date -u<\/strong> creates a snapshot with UTC Timestamp. Also in smb.conf <strong>shadow:localtime<\/strong> has to configure to <strong>no<\/strong><\/p>\n<p>And a Snapshot of project1<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev ~ # btrfs subvolume snapshot -r \/mnt-projects\/projects\/project1 \/mnt-projects\/.snapshots\/project1\/@GMT_`date -u +%Y.%m.%d-%H.%M.%S`\r\n<\/pre>\n<p>Copy more data to the share&#8230;.and try to access the Previous Version tab.<\/p>\n<p>Some further helpful commands<br \/>\nList all snapshots of a subvolume<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev ~ # btrfs subvolume list \/mnt-home\/homes\r\n<\/pre>\n<p>Delete a snapshot <\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@debdev ~ # btrfs subvolume delete \/mnt-home\/.snapshots\/@GMT_2018.10.16-21.31.48\r\n<\/pre>\n<p>Michael<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, this post describes how to setup samba to provide filesystem snapshots to Windows in its &#8220;Previous Versions&#8221; tab. Install your prefered Linux Distribution. In this tutorial debian 9 stretch.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[870,3,1256],"tags":[224,1258,1122,1259,1260,197],"class_list":["post-5800","post","type-post","status-publish","format-standard","hentry","category-debian","category-linux","category-samba","tag-linux-2","tag-previous-versions","tag-samba","tag-sample-samba-config","tag-setup-for-workgroup","tag-snapshot"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/5800","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/comments?post=5800"}],"version-history":[{"count":57,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/5800\/revisions"}],"predecessor-version":[{"id":6015,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/5800\/revisions\/6015"}],"wp:attachment":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/media?parent=5800"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/categories?post=5800"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/tags?post=5800"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}