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.

2 Answers 2


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

# 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].
  • 1
    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, 2012 at 10:45
  • 2
    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, 2012 at 11:14

When I do this type of backup script, I just mount whichever of my backup disks is attached at the time. Obviously they are labelled BackupDisk1, BackupDisk2...

if mount /dev/disk/by-label/BackupDisk* /snapshots
    # rest of backup script goes here
    logmsg "Unable to mount external drive."

This way, the timing of the disk swap is not critical and the script can't get "out of sync" with the disk being used.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .