(ve):Backing Up Ubuntu
- This page was last modified on July 11, 2011, at 14:08.
From (mt) Community Wiki
Run the following commands to backup your Ubuntu (ve) Server. This should apply to Debian as well. Backups will be placed in a /var/backups directory. Also, please make sure you have sufficient space to hold this compressed file and if you do not please use the pipe backup to SSH command, Running df -h or du (with human readable flag) from the command line should give you a rough idea.
df -h
Filesystem Size Used Avail Use% Mounted on /dev/vzfs 39G 1.5G 37G 4% / ...
du . --human-readable --total | grep total
1.9G total
According to the FHS which Ubuntu strictly follows (and you should too) because of upstream we need to create a backups folder that does not reside inside of root, it should reside in var, so lets go ahead and make our /var/backups if it doesn't exist, theoretically because of Debian it should exist on all Debian based systems.
sudo mkdir /var/backups
sudo tar -cvpzf --same-owner \ /var/backups/server-backup_`date +%Y-%m-%d-%H-%M-%S`.tar.gz \ --exclude=/var/backups/server-backup_* \ --exclude=/proc \ --exclude=/lost+found \ --exclude=/sys \ --exclude=/mnt \ --exclude=/media \ --exclude=/dev \ --exclude=/usr/tmp \ --exclude=/usr/local/tmp \ --exclude=/tmp
Debian and Ubuntu users who are space conservative but not CPU conservative can use Bz2 which creates a tighter compression and smaller backup, it does however, take twice, sometimes thrice as long, most system administrators opt to do a nightly Bz2 image of the server when it's off-peak so that they are not eating up valuable CPU time.
sudo tar cvpjf --same-owner \ /var/backups/server-backup_`date +%Y-%m-%d-%H-%M-%S`.tar.gz \ --exclude=/var/backups/server-backup_* \ --exclude=/proc \ --exclude=/lost+found \ --exclude=/sys \ --exclude=/mnt \ --exclude=/media \ --exclude=/dev \ --exclude=/usr/tmp \ --exclude=/usr/local/tmp \ --exclude=/tmp
For users who are low on space, but have enough for a quick backup and delete can put it onto a secondary server as a pipe without allocating the entire amount of space, this is the recommended method for all advanced system administrators as storing backups on the same server that's being backed up defeats the purpose of backups by all senses.
sudo tar cvpjf --same-owner \ /var/backups/server-backup_`date +%Y-%m-%d-%H-%M-%S`.tar.gz \ --exclude=/var/backups/server-backup_* \ --exclude=/proc \ --exclude=/lost+found \ --exclude=/sys \ --exclude=/mnt \ --exclude=/media \ --exclude=/dev \ --exclude=/usr/tmp \ --exclude=/usr/local/tmp \ --exclude=/tmp | ssh client_operator@backup.domain.com "dd of=server_backup.tar.bz2"