If, like me, you’ve built your Ubuntu machine using LVM for all partitions except /boot, you can do a live backup of your system using LVM snapshots and the dump tool.
# lvdisplay --- Logical volume --- LV Name /dev/odin/root_1 VG Name odin ... LV Size 30.00 GB ...
Since my root partition is on LVM, I can do a snapshot to get a point-in-time view of the root partition even as the system is running and software is making changes to the filesystem. To create the snapshot:
lvcreate -L 30G -s -n root_1_snap /dev/odin/root_1
The arguments are: lvcreate -L {size} -n {snapshot name} {lvm device path}
Then, you do a dump backup:
# dump 0uf odin.0.img /dev/mapper/odin-root_1_snap DUMP: Date of this level 0 dump: Mon Apr 28 10:52:39 2008 DUMP: Dumping /dev/mapper/odin-root_1_snap (an unlisted file system) to odin.0.img DUMP: Label: none DUMP: Writing 10 Kilobyte records DUMP: mapping (Pass I) [regular files] DUMP: mapping (Pass II) [directories] DUMP: estimated 3130770 blocks. DUMP: Volume 1 started with block 1 at: Mon Apr 28 10:52:46 2008 DUMP: dumping (Pass III) [directories] DUMP: dumping (Pass IV) [regular files] DUMP: Closing odin.0.img DUMP: Volume 1 completed at: Mon Apr 28 10:55:49 2008 DUMP: Volume 1 3120540 blocks (3047.40MB) DUMP: Volume 1 took 0:03:03 DUMP: Volume 1 transfer rate: 17052 kB/s DUMP: 3120540 blocks (3047.40MB) on 1 volume(s) DUMP: finished in 182 seconds, throughput 17145 kBytes/sec DUMP: Date of this level 0 dump: Mon Apr 28 10:52:39 2008 DUMP: Date this dump completed: Mon Apr 28 10:55:49 2008 DUMP: Average transfer rate: 17052 kB/s DUMP: DUMP IS DONE
The arguments are: dump {level}uf {output file} {source device path}
Next, remove the snapshot to keep from hogging LVM space:
lvremove /dev/odin/root_1_snap Do you really want to remove active logical volume "root_1_snap"? [y/n]: y Logical volume "root_1_snap" successfully removed
Optionally, compress the backup image for safekeeping.
gzip /backup/odin.0.img &
The ampersand (&) will make the process run in the background. By doing this, I saved 71.2% of the size, down to an image that was 878MB from 3050MB!
To restore from said backup, assuming you have a ready ext3 partition of the appropriate size: Uncompress it if need be:
gunzip /backup/odin.0.img.gz
Then:
cd / && rrestore rf /backup/odin.0.img