Advertisement

11.19.2008 at 09:12AM PST, ID: 23918585
[x]
Attachment Details

How to write a backup script for two alternating USB drives?

[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.5
Tags:

Linux, Suse Linux Enterprise Server, 9

I want to use two USB drives with FAT32 filesystems to backup data, but I have a problem with mounting and dismounting the drives and I am not sure how to fix it.

Attached is my first attempt at a backup script.
I think my problem stems from several areas:
1.  Variable declaration $BACKUPDEVICE=/dev/sdc1
2.  Mounting the $BACKUPDEVICE
3.  I think I need to prevent the system from automounting the USB disks to the /media folder so that my script can do it's own mount and umount to the /mnt/usbdrive mount point for the backup job only.

Here is the current mount list:
/dev/md0 on / type reiserfs (rw,acl,user_xattr)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
tmpfs on /dev/shm type tmpfs (rw)
devpts on /dev/pts type devpts (rw,mode=0620,gid=5)
/dev/sda1 on /boot type ext3 (rw,acl,user_xattr)
usbfs on /proc/bus/usb type usbfs (rw)
/dev/sdc1 on /media/usb-160500022Dc5:0:0:0p1 type subfs (rw,noexec,nosuid,nodev,sync,procuid,iocharset=utf8) <=== a double up
/dev/sdd1 on /media/usb-160500022Dc5:0:0:0p1 type subfs (rw,noexec,nosuid,nodev,sync,procuid,iocharset=utf8) <=== a double up
> /dev/sdc1 and /dev/sdd1 are mounted to the same moutpoint!!?

Note from the above that nothing is mounted at the $BACKUPMOUNTPOINT and yet the backups have been running to the $BACKUPMOUNTPOINT and fill the disk!! :-\

What is the best way for me to mount these USB file systems to my $BACKUPMOUNTPOINT with consistency to that it can run in an automatic fashion.  I'd like to be able to simply unplug one disk each morning and replace without all this manual intervention.
Also if it is related, what checks could be written for the second paragraph of my script that may assist help with this problem?

Cheers for anyones help.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
#!/bin/sh
#VARIABLES
 DAYOFWEEK=`date +%a`
 BACKUPDEVICE=/dev/sdc1 #FAT32 USB drive
 BACKUPMOUNTPOINT=/mnt/usbdrive
 BACKUPFOLDER=$BACKUPMOUNTPOINT/backup/$DAYOFWEEK
 BACKUPLOG=/home/$DAYOFWEEK-backup.log
#SUMMARY-BACKUPLOG
 
# Checks
# Is device available for mounting? If not write to $BACKUPLOG
# Is backup disk device already mounted?
 
# Mount the USB disk .
#mount [-fnrsvw] [-o options [,...]] device | dir
 mount -o shortname=winnt $BACKUPDEVICE $BACKUPMOUNTPOINT
 
#Ensure backup folder exists
 mkdir -p $BACKUPFOLDER
 
# Backup data
# /home, /etc ,/var and /root to the FAT32 external USB drive.
# rsync
# -v   verbose output
# -r   recurse into directories
# -l   copy symlinks as symlinks
# -t   preserve times
# --delete delete destination files that don't exist at source
# --modify-window=1 for fat32 compatibility
# no -og options to avoid chown errors
 
 echo "### Backup- /home/data ###"                                        >> $BACKUPLOG
 rsync -vrlt --stats --delete --modify-window=1 /home/data  $BACKUPFOLDER  > $BACKUPLOG
#tail to summary backup log
 echo "### End /home/data ###"                                            >> $BACKUPLOG
 echo ""                                                                  >> $BACKUPLOG
 
cp /home/$DAYOFWEEK-backup.log $BACKUPMOUNTPOINT/
 
# Unmount the backup disk.
 umount $BACKUPDEVICE
 
Accepted Solution by it4soho:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Author Comment by blokeman:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Expert Comment by it4soho:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Author Comment by blokeman:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Expert Comment by it4soho:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
Author Comment by blokeman:

All comments and solutions are available to Premium Service Members only. Start your 7-day free trial to view the solution to this question.

Already a member? Login to view this solution.

 
 
20081119-EE-VQP-46 - Hierarchy / EE_QW_2_20070628