I use Virtual Box a lot for distro / applications testing purposes.
One of the features I simply love about it is virtual machines snapshots, its saves a state of a virtual machine and is able to restore it to its former glory if something you did went wrong without any problems and without consuming your all hard disk space.
On my live systems I know how to create a 1:1 image of the file system but all the solutions I'v known will create a new image of the complete file system.
Are there any programs / file systems that are capable of taking a snapshot of a current file system, save it on another location but instead of making a complete new image it creates incremental backups?
To easy describe what I want, it should be as dd
images of a file system, but instead of only a full backup it would also create incremental.
I am not looking for clonezilla, etc. It should run within the system itself with no (or almost none) intervention from the user, but contain all the data of the file systems. I am also not looking for a duplicity
backup your all system excluding some folders script + dd
to save your mbr. I can do that myself, looking for extra finesse.
I'm looking for something I can do before doing massive changes to a system and then if something when wrong or I burned my hard disk after spilling coffee on it I can just boot from a liveCD and restore a working snapshot to a hard disk.
It does not need to be daily, it doesn't even need a schedule. Just run once in a while and let it its job and preferably RAW based not file copy based.
To explain cprofitt's answer (as his answer is incremental, as I will explain)...
First you need to know about hard links.
Hard links point to the data that is actually on the disk (the physical location) and you can access the data using the hard link. Each file and directory is a hard link to the location of the data on the physical disk. Therefore if there are two files (hard links) pointing to the same location then the data is only stored once.
The process given by cprofitt involves:
Rotate the backups to create a spot for a new one. ("Today's backup" from yesterday becomes "Yesterday's backup", "Yesterday's Backup" from two days ago becomes "Two Days ago's backup" and so on)
Copy the latest snapshot you have done (e.g. "Yesterday's backup") to the spot for the new one (e.g. "Today's backup"), making new hard links to the existing files without copying the file. So all the files in the new snapshot are pointing to the same location as the previous one.
An illustrated example
In the picture below, files of the same colour that have the same file name are hard links to the same file on disk. Here we are just dealing with two snapshots and a few files, but the example scales. (Except for the fact I am moving snapshots the opposite way to scripts in cproffit's answer)
The process is this:
There is a snapshot of the system.
The snapshot is copies (creating hard links to the existing files)
Rsync is run to update the snapshot. When files are changed, it stores the new file as a new copy on the hard disk (so the older snapshot is not changed). In this example, File B has been changed. Note: we now have only 1 copy of File A and File C and two copies of File B stored on the hard disk
Rotate the snapshots (in this case snapshot 0 'falls off' and is deleted and I rename snapshot 1 to snapshot 0)
Copy the snapshot agin (repeat of step 2)
Rsync again. (Repeat of step 3). Now we have 1 copy of File A and 2 copies of both File B and File C
A simplified version of the [first] script (not to be run, just as a stepping stone) is this:
Now the full script(s) has the full explanation here (as cprofitt linked to) and it is more thorough but it is basically as above. The other script is for grouping snapshots and the other part of cprofitt's answer talks about making the process automatic (using cron) and verifying that the backup was sucessful.
You can change the names, so instead of the directories being called "hourly..." they are called something else and the script is run manually.
To restore the whole lot, copy the latest snapshot (or a previous one) back to the directory you were taking the backups of.
To restore a single file that is still in a snapshot, go the snapshot and copy it back to where it belongs.
The backup media can be a external hard drive (must be ext2/ext3/ext4). If you were backing up
/
(mainly/boot
,/home
,/etc
/root
and/usr
) then, say...You mount the external drive, perform the backup and create the latest snapshot.
Unmount the drive.
Remember you deleted a file (even from the trash) that you wanted.
Connect the external drive and retrieve the file.
Do a backup (just to be sure)
Disconnect the drive and go travelling...
Realise that a laptop and lava do not mix.
With your new laptop running a live cd, format the internal drive, mount you external drive and then
cp -a /media/external/snapshot-0/* /media/internal-drive
(assuming snapshot-0 is the latest snapshot)Install grub to the MBR (yes it has to be seperate) - or use
dd
to backup the mbr, like cprofitt has said at the bottom of his answer.Reboot.
The script needs to be refined (to only get the stuff you want) and the procedure aove assumes that you don't have a
/home
partition. If you do (or had) create a new one on the disk and mount it in place withmount /dev/sdxy /media/external/home
before copying.You could use rsync.
and the second:
After creating the script to your needs add it to cron jobs.
add the following:
They cause make_snapshot.sh to be run every four hours on the hour and daily_snapshot_rotate.sh to be run every day at 13:00 (that is, 1:00 PM).
source: http://www.mikerubel.org/computers/rsync_snapshots/
If you want it to run hourly you would add a cron job for each hour.
Another possible option is using rsnapshot
Install rsnapshot (available in software center)
Configure rsnapshot and Specify Backup Source Directory
Open the /etc/rsnapshot.conf and uncomment the following lines.
Define your destination backup directories in /etc/rsnapshot.conf as shown below. In this example,
/home – source directory that should be backed-up localhost/ – destination directory where the backup will be stored. Please note that this directory will be created under /.snapshots/{internal.n}/ directory as shown in the last step.
nano /etc/rsnapshot.conf
backup /home/ localhost/
Test rsnapshot Configuration
Perform configuration test to make sure rsnapshot is setup properly and ready to perform linux rsync backup.
You can backup linux directories or files at various intervals. By default, the hourly and daily backups are configured.
Verify the hourly backup configuration.
Verify the daily rsnapshot cwrsync backup process is configured properly.
Once you’ve verified that the rsync hourly and daily backup configurations are setup properly in the rsnapshot cwrsync utility, it is time to set this puppy up in the crontab as shown below.
source: http://www.thegeekstuff.com/2009/08/tutorial-backup-linux-using-rsnapshot-rsync-utility/
---- Bare Metal Recovery
I would use dd and tar to do baremetal recovery.
Backup important metadata:
Backup the operating system:
I personally would tend to take my system off-line if I wanted to make a baremetal restore file.
You should take a look at ddar (homepage).
It is incremental in the sense of not transferring the identical parts of the snapshot. It is not incremental in the classical meaning of the word, since it is dealing with snapshots.
Note: I have not tried this myself (but I trust the author). It might not do what you'd like to achieve out-of-the-box, but still there are more similar solutions on the page (eg. ZFS), so as a starting point, it could possibly prove useful.
There are 2 ways to do block based incremental backup
Filesystem based snapshots
Both ZFS and BTRFS provide block based incremental snapshots (BTRFS, ZFS (page 25)). You could have a drive that you rsync to that is either ZFS or BTRFS and snapshot.
There is also LVM snapshots (mentioned by cprofitt) that provide the same block based incremental snapshots.
Program based snapshots
There a several backup programs, however a few stick out for the purpose:
I know you specifically mentioned that you are not looking for something like duplicity, however I thought I might mention some features.
However these programs require you to install them to restore. The beauty of something like rsync is that almost every linux installation has rsync (e.g. tiny core (a 10MB distribution) is missing it) by default.
Duplicity
It just stores the diff (block level) and then compresses and encrypts them. This leads to even less storage than the rsync method, however (at least the way I see it) the filesystem will need to be reconstructed, which will take time (if you are using incremental backups with it, and it depends on the time since last full backup)
The man page explains how it works.
Rdiff-backup
A client-server program that creates, like duplicity, block level diffs, however it stores changes from the lastest restore point, so the latest snapshot is the fastest to restore. Going back in time (not the lastest snapshot) requires more diffs to be analyzed and so it is slower.
Some people compare rdiff-backup to rsnapshot (seems like an more automatic way of the rsync mentod). Almost all the how-tos focus on using rdiff over the network, however I found one which mentions how to do it on localhost.
I think you can do this with LVM its only theorical, and it will waste a largue amount of hard disk. My theory is tha you can get your root system living on a logical volume, then if you want to make a test you can create an snapshot and restart the machine using the new volume.
LVM snapshots need the original volume to work. This is because the new volume holds the difference between the snapshot and the real filesystem.
If you leave the system in this state you'll start to waste disk space as the new filesystem changes. I don't know if there's a way to consolidate the snapshoted and the definitive filesytem. Surely you can dd to another logical volume, but for this you'll need twice the space of your filesystem plus the difference between your "point of recovery" and the current state.
And all of this requires reboots and is far from being automatic.
Its also supposed that several modern filesystems goes this way, like zfs on solaris systems or the experimental btrfs.
This one is a bit over my head, but it sounds like part of what you want to do is make partial backups of binary files (like partition image files). There's a package designed to do that (I've just read about it - not tried it.)
Take a look at bup.
https://github.com/apenwarr/bup
It might give you some ideas.