Regular backup with rsync and cron

This is nothing new, just for me to remember. We use rsync and cron to make a backup of all home directories regularly. There will be a weekly backup that is readily accessible and a zipped monthly backup.

First, we need to install rsync (this is for Ubuntu, replace with the package manager of your choice):

apt-get install rsync

Then we need to create the directories where we want to save the backups. Here I am putting it into /media/backup for no particular reason, use any directory you like.

mkdir /media/backup/weekly
mkdir /media/backup/monthly

Next the command that actually copies the files:

rsync -a --exclude=".*/" --delete /home/ /media/backup/weekly

The command uses rsync, which is the tool for the job. We want to backup the complete folder home with all the directories contained in there. We exclude hidden files (starting with .) to avoid copying .cache and other temporary files. You may want to refine this setting for your case. The option --delete overwrites the files in the target directory /media/backup/weekly. So last week’s data will be overwritten with this week’s data when the backup runs. I’d suggest running this command directly to see what happens before proceeding with the automation.

Now that we know how to copy the data, we just need to execute this command regularly. This is done with cron via this command:

crontab -e

This opens an editor with all cron jobs that are currently set up. Add two lines for the backup:

00 18 * * 5 rsync -a --exclude=".*/" --delete /home/ /media/backup/weekly
00 6 1 * * tar -cjf /media/backup/monthly/monthly_$(date +%Y%m%d).tar.bz2 /media/backup/weekly/

The numbers in the beginning of each line give the minutes, hours, day, month and day of the week. The rest of each line is the command. The first line copies the data to /media/backup/weekly on every Friday afternoon (at 18:00). So we will always have a backup that is at most a week old. The second line is executed on every first day of the month at 6:00 and copies the data to /media/backup/monthly in a zipped form.

Load home directories from a server

The setting is the following: I have a pool of 24 computers and about 20 students who need to be able to login at any of the computers and access their data. Basically the normal setup of a computer pool. Of course there are many solutions for this problem (LDAP and so on), but of course it is more fun to create your own solution!

The basic idea is that the home directories are loaded from the server and overwrite the home directories of the clients. The accounts are created directly on each computer, but a user has the same user ID on every computer, so that the mapping of permissions works.

Now for the details. First the server. As a first step, install the NFS server package:

apt-get install nfs-kernel-server

Configure what should be exported. This is done in the file etc/exports:

vi /etc/exports

We want to export the folder /home/ and make it available for all computers in our pool (the subnet 1.22.333.* – of course that’s not the correct IP). So we add this line to the file:

/home/  1.22.333.0/255.255.255.0(rw,async)

We re-read the configuration to let the changes take effect:

exportfs -ra

Now we can check if the correct folder is exported:

exportfs -v

Finally, we create all student accounts on the server. This will also create a home directory for each one. We use fixed user IDs, so for example we will have hans with UID 1010, lisa with UID 1011, kim with UID 1012, and so on.

Now for the clients, where as a first step we need to install the NFS package for the client:

apt-get install nfs-common

Now we could mount the exported folder from the server by hand, but because we want to mount them permanently, we will use the global fstab file for this:

vi /etc/fstab

In this file, insert the following line (where 1.22.333.4 is the server IP):

1.22.333.4:/home/    /home/  nfs     rw,soft 0       0

Restart the computer for the changes to take effect. And finally, again, we need to create all student accounts on each computer and take care to assign the same UID.

Empty panel in XFCE

XFCE has a very annoying property for new users. When you start the desktop for the first time, it asks whether you want to use the “empty panel” or the “default panel”. Unfortunately, people who are new to Linux (and even some that are not so new) have no idea what the question is asking. What you usually want to click is “default panel”. Clicking on “empty panel” will usually result in unhappy users – the desktop will be completely empty. Nothing there, not even a logout button. Bad luck for the newbie.

So in a pool where I expect most users to know little to nothing about Linux, it may be a good idea to simply remove the question completely. This can be done by copying the default panel to a specific place (why? don’t ask me – but it works):

cp /etc/xdg/xfce4/panel/default.xml /etc/xdg/xfce4/xfconf/xfce-perchannel-xml/xfce4-panel.xml

If the user already clicked ’empty panel’, the above doesn’t work. What you can do is to get the question back by removing a few files:

rm -r ~/.config/xfce4/xfconf
rm -r ~/.config/xfce4/desktop
rm -r ~/.cache/sessions/