Tuesday, December 29, 2009

Mount USB Key for sipXecs Backups

Ok, so you don't want to bother setting up an FTP server to store backups of your sipXecs system. Here's how to mount a USB Key to your backup folder.

Most USB keys will setup SCSI drive device (in my case it was /dev/sda1). Plug in a USB key and check out the /var/log/messages file to see what device was created.

You'll want to get a little program installed on your system called 'scsiadd'. This allows you to remove USB scsi devices from the system without causing them damage. It's available here: http://llg.cubic.org/tools/

The following assumes you are logged into the system as root...

Add required packages:
yum install lsscsi

If you don't have development tools on your sipXecs system yet, add them:
yum install gcc gcc-c++ kernel-devel

Download, build and install scsiadd:
cd $HOME
mkdir scsiadd
cd scsiadd
wget http://llg.cubic.org/tools/scsiadd-1.97.tar.gz
tar -xf scsiadd-1.97.tar.gz
cd scsiadd-1.97
./configure
make install


Command line options:

scsiadd 1.97 - add and remove devices from the scsi subsystem
---------------------------------------------------------------
syntax: scsiadd {-a|-r}
scsiadd {-a|-r}
scsiadd {-a|-r}
scsiadd {-a|-r}
scsiadd [-i maxid] -s
scsiadd [-i maxid] -s
scsiadd -p
parameters not given are assumed 0
-a: add a device (default if no command given)
-r: remove device
-s: scan for devices
-p: print scsi status
-h: print this help message
-i: maximum SCSI ID which is scanned

Here's a good blog article on using scsiadd: http://blog.shadypixel.com/safely-removing-external-drives-in-linux/

Essentially, to remove a scsi device while the system is running, first find the device with lsscsi and then use scsiadd -r to remove it...

[root@sipx scsiadd-1.97]# lsscsi
[3:0:0:0] disk CBM USB 2.0 5.00 /dev/sdb
[root@sipx scsiadd-1.97]# scsiadd -r 3
could not remove device 0 0 3 0 : No such device or address
[root@sipx scsiadd-1.97]# scsiadd -r 3 0 0 0
[root@sipx scsiadd-1.97]#

Ok, now let's get to making the USB work:

Convert your USB drive from FAT16 or whatever it is to ext3:

mkfs.ext3 /dev/sda1

Modify /etc/fstab:

nano -w /etc/fstab

Add the following line at the bottom:

/dev/sda1 /var/sipxdata/backup vfat auto,user,rw,sync 0 0

Test your fstab file now:

mount -a

And check to see that it is mounted:

mount

Change ownership on backup folder:

chown -R sipxchange:sipxchange /var/sipxdata/backup

Perform a test backup from the GUI.

4 comments:

Anonymous said...
This comment has been removed by a blog administrator.
Michael Picher said...

Need to change /dev/sda1 to /dev/sda.

also, change mount command.

after mount command, chown sipxchange:sipxchange /var/sipxdata/backup

change vfat to ext3

John A said...

Mike, seems to work fine. I just used ext3 in the fstab. the device name can be different... mine was /dev/sdb

just check often using lsscsi to make sure...
thanks!

John Armentrout said...

Mike, I thought I'd post a variation on your entry so that it makes a *copy* of the contents of the backup directory rather than replaces it. I figure two copies of a backup file are better than one, especially if they are on different media.... (FYI, I am certainly no Linux master, but this seems to work)

insert a USB stick, I used an 8G
notice what device it is by watching the console.
if you don’t notice use:

lsscsi

to find out. Mine came in at /dev/sdb

make a new ext3 file system on the USB stick:

mkfs.ext3 /dev/sdb

cd /var/sipxdata
mkdir backup2
chown -R sipxchange:sipxchange backup2


(probably unnecessary as the copy will run as root)

cd /etc
nano -w fstab


add the following to the end of the file and save:

/dev/sdb /var/sipxdata/backup2 ext3 auto,user,rw,sync 0 0

now...
mount -a
mount
(to check to see that it mounted /dev/sdb at backup2)

now create a cron job to copy backups from the normal backup location to the new...

cd /var/cron.daily
nano -w sipx-copybackup


and add these lines which do a copy/update to the backup2 location. (Note that perhaps should check space or delete things old or something...):

#!/bin/sh
# JCA script to copy backups (sync) to a mounted usb stick
cp -ru /var/sipxdata/backup/* /var/sipxdata/backup2

save the file
now make it executable:

chmod a+x sipx-copybackup

if you want to try it now:

./sipx-copybackup

this could take a while to run, but you should see the light on the USB stick blinking... It should run each night and copy anything new in the /var/sipxdata/backup directory to the USB stick.