Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We have an external drive that our server backs up to nightly. It is mounted to /snapshots. We are planning to swap this disk out each week. The problem is that one drive comes up as /dev/sdc and the other as /dev/sdd. In the fstab the mount is set to /dev/sdc. Before backing up a scripts runs to mount /snapshots which gets its mount point from fstab.

How can I get it to mount /dev/sdc one week and /dev/sdd the next week. It has to be automatic as the people who swap the disk over will not be going into the terminal.

share|improve this question
up vote 2 down vote accepted

You can create one crontab for every week 0 2 * * 2 /usr/local/ and put in :

# check whether the job runned last week
if [ -e $mark_file ] ; then
  rm -f $mark_file
  unmout /snapshots
  mount /dev/disk/by-label/even-weeks /snapshots
  touch $mark_file
  unmout /snapshots
  mount /dev/disk/by-label/odd-weeks /snapshots

The script will not find $mark_file on the first run, so it will mount /dev/disk/by-label/even-weeks. On the second run the script will remove $mark_file and then mount /dev/disk/by-label/odd-weeks. For the third run, it is the same as the first run. So if this script is run weekly by cron, the job command will run every two weeks.

Tips : Label your disk ln -s /dev/disk/by-uuid/UUID /dev/disk/by-label/even-weeks


  • Correction after the comment @Mat.
  • From the comment of @nearora : Label yours filesystems with links to /dev/disk/by-id/ instead of use /dev/sd[a-z].
share|improve this answer
You'll need to exit in the sdc case or pull the sdd case in the if branch, otherwise you'll be doing mount sdc, unmount, mount sdd. – Mat May 28 '12 at 10:45
Of course @Mat ! Thanks – Yohann May 28 '12 at 10:50
Instead of using /dev/sd[a-z] use links in /dev/disks/by-id/. Give your ext2/3 filesystems a label and they'll show up there! – nearora May 28 '12 at 11:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.