Example Two - Creating /etc Backups
The second example is about something more pratical. Modern Linux'es have all their important files under the /etc directory tree. Since we are going to access the /etc files you should become root.
backup-etc is a simple shell script that archves the /etc directory tree under /var/backup/etc (the directory is created if it does not exists). The script can be called without any other preparation or command line parameters. On my system I get
# ./backup-etc 0007 0007-20060105 wcp: ignoring file 40 Colors
This shows two things. First this is the 7th backup I'm doing on my system. Second wcp ignores files that have blanks in their names, in this example "40 colors" which is a file in the directory /etc/kde/colors. This is a limitation I will perhaps remove in a later version, but for now it's simply like that.
Since wcp is run as root, the server space is local and hence wcpd runs also as root, the archive features differ from archive made as non-superuser.
- User and group ownerships are maintained:
# ls -l /etc/identd.key -rw------- 1 identd root 1024 Jun 11 2005 /etc/identd.key # ls -l /var/backups/etc/0007-20060105/identd.key -rw------- 8 identd root 1024 Jun 11 2005 /var/backups/etc/0007-20060105/identd.key
- Character and block special files also:
# cp -a /dev/tty0 /etc # backup-etc 0008 0008-20060105 wcp: ignoring file 40 Colors # ls -l /var/backups/etc/0008-20060105/tty0 crw-rw---- 1 root root 4, 0 Jan 5 12:34 /var/backups/etc/0008-20060105/tty0 # rm /etc/tty0
This feature is limited to superuser mode since normal user are usually not allowed to create special files like device drivers.
As a quick summaryWhen run as root wcp and wcpd try to maintain as much file attributes as possible.
Things are more difficult when running in a mixed setup (wcp local, wcpd on a remote host) with one side as root and the other not. The basic rule is that the superuser side tries to maintain all file attributes while the non-root side cares only about the last modification time and filesize.
You can use backup-etc as ready-to-use script to make regular backups of your /etc directory
- manually from the command line,
- driven by cron,
- at boot time,
- using a local or remote archive space.
Creating local /etc backups protects you against configuration or handling mistakes but not agaist disk crashes, for this backups to another server are required. Remote can be done with a command like
# wcp store /etc ssh://root@backup-server/var/backups/$HOSTNAME
which arcives the local /etc tree on backup-server under /var/backups.
Since wcp does not store any local information, you can also mix local and remote backups. The files that have to be copied to the server depend only on the last archive version on the destination. Or in other words
It's especially possible to mix e.g. manual local and automatic remote archive runs, wcp knows which files to copy. See "Example Four - Running a Central Backup Server" for more information about remote backups.
backup-etc supports the following command line options.
- -n label
append label to the automatic generated version name which is 4 digit version number followed by the current date.
- -s server
select another server locataion than the default /var/backup/etc.
- -- options
- Options following two dashes are passed as options to wcp's store operation.
backup-etc's default server location may be set in it's default file /etc/default/backup-etc.