Today I wanted to try out something new (file system snapshots)
It's pretty interesting method of making file backups, all tough backups are still required.
To demonstrate how snapshots work I will use virtual disk (This is 1st time I do it, and I don't want to experiment on my system, not to mention that I'm doing this over ssh)
I will show all steps as if I was root
-1) What is snapshot, what do I need to make one?
* You need UFS file system with enough free space.
If you run out of space during creation of snapshot, you will have problems (system may even start to panic)
* You need root access
* FreeBSD
0) Preparing Virtual disk
1) Mounting the disk
to be able to make snapshots you need to mount disk with snapshot flag
to do it manually:
to mount disk at boot time and be able to take snapshots add snapshot to flags field
example
2) Copy some files to file system
3) Make snapshot
mksnap_ffs takes two arguments:
fs mount point and snapshot name
you can have up to 20 snapshots at any time per file system, and to remove snapshot all you need to do is simply find it and remove it with rm
Now you have your file system snapshot saved to fresh.
4) modify fs and make new snapshot
now you have 2 snapshots of your filesystem.
5) What next?
when you have snapshots of file system you can fsck them, dump it, mount snapshot as if you fs was frozen in time
But the interesting thing is that you can recover your files after deleting them, or simply view them.
to restore fs from snapshot with dump/restore:
that fs should only have snapshots
TIP: i suggest marking snapshots with nodump flag
right after they are created
I made snapshot of 39GB fs in about 3 min (isn't that great?)
and using -h 0 switch when dumping snapshot
That way you can keep snapshots on fs when restoring fs from snapshot with dump/restore
A great thing about snapshot is that it can be burned to cd as regular file, and used later to restore fs.
It's very easy to make snapshots everyday with crontab.
finally when you don't need snapshot simply rm it.
Also when using snapshots you will (in most cases) need much less space compared to when using dumps
I made snapshot of 70GB fs (39GB used) in about 3 min (isn't that great?), and because fs wasn't modified, it's still only 39GB used
All in all, I'm happy I tried snapshots. Now I will need to redesign my FreeBSD setup a bit, to take full use of this wonderful technology. I believe it will make my life so much easier
One more thing. You can only save snapshot to same device you're making snapshot of.
Resources:
Handbook >> snapshots
mksnap_ffs(8)
P.S. I hope what i wrote makes sense to you. lol
If you need help, ask here, I'll try to help
EDIT:
you can't make snapshot of root fs
Don't add snapshot in /etc/fstab for root or you won't be able to boot in multiuser mode
EDIT 2:
You can use labels with snapshots
EDIT 3:
Instead of copying snapshots to some other media, I suggest extracting dumps and compressing them with gzip. That way you will save a lot of space, because when you make snapshot and copy it to other media it will be same size as original file system.
Dump will be significantly smaller in most cases. And it will be much faster to compress.
It's pretty interesting method of making file backups, all tough backups are still required.
To demonstrate how snapshots work I will use virtual disk (This is 1st time I do it, and I don't want to experiment on my system, not to mention that I'm doing this over ssh)
I will show all steps as if I was root
-1) What is snapshot, what do I need to make one?
* You need UFS file system with enough free space.
If you run out of space during creation of snapshot, you will have problems (system may even start to panic)
* You need root access
* FreeBSD
0) Preparing Virtual disk
Code:
$ dd if=/dev/zero of=~/test.img bs=1 count=1 seek=10000000000
$ mdconfig -at vnode -u 1 -o noreadonly -f ~/test.img
$ newfs -U /dev/md1
1) Mounting the disk
to be able to make snapshots you need to mount disk with snapshot flag
to do it manually:
Code:
mkdir ~/mnt
mount -o snapshot /dev/md1 ~/mnt
to mount disk at boot time and be able to take snapshots add snapshot to flags field
example
Code:
/dev/ad0s1d /usr ufs rw,snapshot 2 2
2) Copy some files to file system
Code:
$ cp -R /path/to/some/files1 ~/mnt/
$ cp -R /path/to/some/files2 ~/mnt/
$ cp -R /path/to/some/files3 ~/mnt/
$ cp -R /path/to/some/files4 ~/mnt/
3) Make snapshot
mksnap_ffs takes two arguments:
fs mount point and snapshot name
you can have up to 20 snapshots at any time per file system, and to remove snapshot all you need to do is simply find it and remove it with rm
Code:
$ mksnap_ffs ~/mnt fresh
Now you have your file system snapshot saved to fresh.
4) modify fs and make new snapshot
Code:
$ rm -R ~/mnt/files2
$ mksnap_ffs ~/mnt modifiedfs
now you have 2 snapshots of your filesystem.
5) What next?
when you have snapshots of file system you can fsck them, dump it, mount snapshot as if you fs was frozen in time
But the interesting thing is that you can recover your files after deleting them, or simply view them.
to restore fs from snapshot with dump/restore:
Code:
$ cd ~/mnt
$ rm -R files*
$ dump -0af - fresh | restore -rf -
TIP: i suggest marking snapshots with nodump flag
Code:
$ chflags nodump ~/mnt/fresh
I made snapshot of 39GB fs in about 3 min (isn't that great?)
and using -h 0 switch when dumping snapshot
Code:
$ dump -h 0 -0af - fresh | restore -rf -
A great thing about snapshot is that it can be burned to cd as regular file, and used later to restore fs.
It's very easy to make snapshots everyday with crontab.
finally when you don't need snapshot simply rm it.
Also when using snapshots you will (in most cases) need much less space compared to when using dumps
I made snapshot of 70GB fs (39GB used) in about 3 min (isn't that great?), and because fs wasn't modified, it's still only 39GB used
All in all, I'm happy I tried snapshots. Now I will need to redesign my FreeBSD setup a bit, to take full use of this wonderful technology. I believe it will make my life so much easier
One more thing. You can only save snapshot to same device you're making snapshot of.
Resources:
Handbook >> snapshots
mksnap_ffs(8)
P.S. I hope what i wrote makes sense to you. lol
If you need help, ask here, I'll try to help
EDIT:
you can't make snapshot of root fs
Don't add snapshot in /etc/fstab for root or you won't be able to boot in multiuser mode
EDIT 2:
You can use labels with snapshots
EDIT 3:
Instead of copying snapshots to some other media, I suggest extracting dumps and compressing them with gzip. That way you will save a lot of space, because when you make snapshot and copy it to other media it will be same size as original file system.
Dump will be significantly smaller in most cases. And it will be much faster to compress.