Penguin
Diff: SambaShadowCopyHowto
EditPageHistoryDiffInfoLikePages

Differences between version 8 and previous revision of SambaShadowCopyHowto.

Other diffs: Previous Major Revision, Previous Author, or view the Annotated Edit History

Newer page: version 8 Last edited on Tuesday, May 2, 2006 12:55:40 pm by CraigBox Revert
Older page: version 6 Last edited on Friday, April 28, 2006 11:57:12 am by CraigBox Revert
@@ -51,9 +51,9 @@
 5. Configure Samba. 
  
 I have used something a little like this: 
  
-<pre
+<verbatim
 [data] 
  comment = Snapshotted storage 
  path = /array/storage 
  read only = no 
@@ -62,22 +62,22 @@
  force directory mode = 0775 
  force group = "MYDOMAIN+Domain Users" 
  writeable = yes 
  vfs objects = shadow_copy 
-</pre
+</verbatim
  
 The important part is, of course, the shadow_copy VFS module. 
  
 You end up with an /array/storage directory that looks like this: 
-<pre
+<verbatim
 drwxr-xr-x 8 root MYDOMAIN+domain users 4096 2006-05-02 12:14 . 
 drwxr-xr-x 3 root root 4096 2006-04-27 11:28 .. 
 drwxr-xr-x 8 root MYDOMAIN+domain users 4096 2006-05-02 07:00 @GMT-2006.05.02-07.00.00 
 drwxr-xr-x 9 root MYDOMAIN+domain users 4096 2006-05-02 12:00 @GMT-2006.05.02-12.00.00 
 drwxr-xr-x 9 root MYDOMAIN+domain users 4096 2006-05-03 07:00 @GMT-2006.05.03-07.00.00 
 drwxr-xr-x 7 root MYDOMAIN+domain users 148 2006-05-03 12:00 @GMT-2006.05.03-12.00.00 
 drwxrwxr-x 2 root MYDOMAIN+domain users 31 2006-04-27 14:56 public 
-</pre
+</verbatim
  
 Samba presents you all of this, @GMT-date dirs and all. Seems you have to have this - you can't share /array/storage/public and have the shadow copies work (see point 2, above). 
  
 5. Create some scripts to do the work for you. 
@@ -85,16 +85,57 @@
 !Scripts 
  
 OK, here's the fun part. 
  
-I have created a rotation I call 'halfdaily', matching Windows 2003 by taking snapshots at 7am and 12pm; "before work" and "before lunch". 
+Because of the way LVM snapshots are created, you assign the amount of space for the changes you think will be made to it. If you assume you will have 1GB of changes every day and will keep snapshots for five days, you could make all your snapshots just over 5GB (including overhead).  
+  
+I'm being a bit smarter. I'm creating the snapshot at 1GB, and then I'm growing it to 2GB on the second day, 3GB on the third day, etc.  
+  
+For this example, I have created a rotation I call 'halfdaily', matching Windows 2003 by taking snapshots at 7am and 12pm; "before work" and "before lunch". 
  
 ; /etc/snapshots/halfdailytab : The table of snapshot date/times. Scripts will mount and umount these at boot/shutdown, and rotate them as appropriate. 
  
-; /usr/local/sbin/create-snapshot : Creates a snapshot. 
+; /usr/local/sbin/create-snapshot : Creates and mounts a snapshot. Parameters is the snapshot name, which is the time of its taking (in ''date +%Y.%m.%d-%H.%M.%S'' format), and an optional snapshot size (in LVM format, ie 20M, 5G).  
+  
+; /usr/local/sbin/create-snapshot-now: Calculate the time now and create/mount a snapshot with that time, and default snapshot size defined in <tt>create-snapshot</tt>  
+  
+; /usr/local/sbin/remove-snapshot : Removes, unmounts, and removes the mount point for a snapshot. Parameter is the snapshot name.  
+  
+; /usr/local/sbin/grow-snapshot : Wrapper for lvextend; grows the snapshot in $1 by the size specied in $2, or by the default growth size defined in the script.  
+  
+; /usr/local/sbin/mount-all-snapshots : Mounts LVM snapshots into their directories. Intended for use at boot time. Call it with a number of snapshot table files, ie <tt>mount-all-snapshots /etc/snapshots/halfdailytab</tt>; if you have another rotation, you can specify more than one table.  
+  
+; /usr/local/sbin/umount-all-snapshots : As the name suggests, unmounts the snapshots listed in the table specified on the command line; intended for use at system shutdown time.  
+  
+; /usr/local/sbin/rotate-halfdaily-snapshots : This script brings it all together. Defined in it are a number of snapshots to keep, snapshot growth size, and the table to keep them in.  
+  
+! How to set it up  
+  
+Put this in /etc/cron.d/snapshots:  
+  
+<verbatim>  
+# 7am and 12pm every day  
+0 7,12 * * * /usr/local/sbin/rotate-halfdaily-snapshots  
+</verbatim>  
+  
+Put mount-all and umount-all in your startup sequence (FIXME: write this bit)  
+  
+At 7am and 12pm every day, the script will run. It will see if it needs to expire a snapshot (if there are already the maximum number), and do so if required. It will grow all the snapshots by the defined increment, and it will create a new snapshot.  
+  
+! Extra for experts  
+  
+If you want, you can have multiple rotations; it would make sense to have half days for the last 2 days and days for the last week; you can do this by having another table, /etc/snapshots/dailytab, and creating a rotate-daily-snapshots script to match. (Be sure to up the snapshot size).  
+  
+! Conclusion  
+  
+Congratulations; all going well you should have a Samba share with shadow copies. You can test it by editing a file, running <tt>create-snapshot-now</tt>, and editing the same file. After changing it, you should see a "Previous versions" tab appear on the files properties, with the time that you took your snapshot. 
  
+! Notes:  
  
+* If you don't change the file, you don't see previous versions for it.  
+* You can do previous versions on directories, as well as files.  
+* The snapshots will appear to the Linux machine to be complete copies of the filesystem at that point in time; with the proviso that they are read-only, you can do what you like with them.  
  
 !Links 
  
 * [How to use the Shadow Copy client|http://www.petri.co.il/how_to_use_the_shadow_copy_client.htm] 
 * [Some useful information about XFS & snapshots|http://c.mills.ctru.auckland.ac.nz/Samba/XfsAclWinAuth.html]