Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I have a centos4.4 box with a simple samba server that I'm using for backups-to-file of 2 2003 servers. I would like to be able to plug in an external usb drive, have it copy the previous nights backup to the drive, then unmount the drive. The external drive only has the capacity to store 1 set from each server.
5-day rotation, monday-friday. All backups are stored in /backupsvr/<first 3 letters of the day of week>/svr<X>.bkf (X = 1 or 2, depending on which servers set). Usb drive mounts as /media/usbdisk.
I guess the first question is can a script be triggered by a drive being mounted?
Other than that I have psuedo-code that I've done in my head, but have had trouble implementing:
-Plug-in drive (trigger script)
-use the `date` command to determine day of week
-if $date=mon, cp (-f to overwrite? needed?) /backupsvr/fri/*.bkf /media/usbdisk/, umount drive
-if $date=tue, cp /backupsvr/mon/*.bkf /media/usbdisk/, ...etc.
</end of psuedo-code>
Unfortunately I'm swamped this week, and am being hounded about the off-site backup. I wouldn't ask unless I really needed the help, I am usually pretty good at figuring this stuff out, and I figure this might take 30 seconds for someone more familiar with bash scripting.
Edit: Ahh, a thought. If it's not possible to trigger a script by a mount, maybe just a cron job that runs every 5 minutes, 8am-5pm, to see if /media/usbdisk (or /dev/sda1) is mounted, and if so, trigger the cp script. The linux box pretty much just sits idle during working hours anyway. Arg, what happens 5 minutes into the cp though...
Better yet, have this script start up on boot and run all the time. A loop detects whether the drive is mounted. If it's not, sleep 300 seconds and go back to the top of the loop. If it's mounted, then do your stuff.
Then check every minute or so for the drive to become unmounted. When it is, go to the top of the loop and wait for the drive to become mounted again.
Have fun writing the script!
Last edited by firstname.lastname@example.org; 05-01-2007 at 04:00 PM.
Edit2: It never shows up in the svrs mtab. I can mount it manually, but it won't automount. Maybe it's just because of different h/w. Gah, don't have the time to mess with it. All the h/w is at the office so I can't test after hours. Oh well.
Ok here it is. Probably bass-ackwards, mutilated, and ugly, but most of it seems to work. Haven't had a chance to test the 'donetoday / sleep 10h' part, but oh well. Launching it using '/etc/rc.local'. I might eventually redirect the cat/grep line to null, it outputs to the screen, but it's headless anyways.
while [ "$x"="1" ]
if [ "$donetoday" = "1" ] ; then sleep 10h && donetoday="0" ; else
cat /etc/fstab | grep sda1
if [ "$attached" = "0" ] ; then
mount -t vfat /dev/sda1 /media/usbdisk
case "$day" in
1) cp -u /backupsvr/fri/*.bkf /media/usbdisk/ && umount /dev/sda1 && donetoday="1" ;;
2) cp -u /backupsvr/mon/*.bkf /media/usbdisk/ && umount /dev/sda1 && donetoday="1" ;;
3) cp -u /backupsvr/tue/*.bkf /media/usbdisk/ && umount /dev/sda1 && donetoday="1" ;;
4) cp -u /backupsvr/wed/*.bkf /media/usbdisk/ && umount /dev/sda1 && donetoday="1" ;;
5) cp -u /backupsvr/thu/*.bkf /media/usbdisk/ && umount /dev/sda1 && donetoday="1" ;;
Know what? Now that I look at my above post, I probably should of posted this in programming.
Well, didn't work, and it's kind of a 'duh' moment. External drive was formatted fat32 (mount -t vfat ...), 4gb filesize limit. Now the decision of formatting it as ext3 or ntfs, but I'd like to be able to restore from the usb drive without a linux box needed. Maybe a small ntfs partition with a 'ext4win' type driver, or setting up ntfs rw on the backupsvr.