Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
add comment

1 Answer 1

up vote 2 down vote accepted

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

#!/bin/bash
mark_file=/tmp/job-run-marker
# 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
else
  touch $mark_file
  unmout /snapshots
  mount /dev/disk/by-label/odd-weeks /snapshots
fi

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

EDIT :

  • 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
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 '12 at 10:45
    
Of course @Mat ! Thanks –  Yohann May 28 '12 at 10:50
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 '12 at 11:14
add comment

Your Answer

 
discard

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.