Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 08-19-2005, 04:24 AM   #1
Registered: Jul 2005
Location: Belgium
Distribution: Debian
Posts: 38

Rep: Reputation: 15
Backup script

How difficult would it be to write a PERL script (for someone who has never worked with PERL before) for Debian that works like this:

1. Run a check to see if there are any devices connected (the device will always be an external harddisk) to the USB ports at a predefined moment
2. If this check is positive, mount the external harddisk
3. Make an incremental backup from certain maps to the external harddisk
4. unmount the harddisk
Old 08-19-2005, 04:51 AM   #2
Registered: Nov 2004
Location: BIOS
Distribution: RHEL3.0, FreeBSD 5.x, Debian 3.x, Soaris x86 v10
Posts: 379

Rep: Reputation: 30
It can be written in Perl, but it can be done in shell scripting too.
See script it has some logic Only it does backup to windows server; so you can easily modify it for your need

Last edited by nixcraft; 08-19-2005 at 12:04 PM.
Old 08-19-2005, 06:29 AM   #3
Registered: Jul 2005
Location: Belgium
Distribution: Debian
Posts: 38

Original Poster
Rep: Reputation: 15
Thanks, I'll check it out
Old 08-22-2005, 01:58 AM   #4
Registered: Jul 2005
Location: Belgium
Distribution: Debian
Posts: 38

Original Poster
Rep: Reputation: 15
mount /dev/usb-harddrive
# Author: Brice Burgess
# -- backup to a local drive using rsync
# Directories to backup. Separate with a space. Exclude trailing slash!
# Directory to backup to. This is where your backup(s) will be stored.
# Exclude trailing slash!
# Comment out the following line to disable verbose output
if [ ! -x $TARGET ]; then
echo "Backup target does not exist or you don't have permission!"
echo "Exiting..."
exit 2
echo "Verifying Sources..." 
for source in $SOURCES; do
echo "Checking $source..."
if [ ! -x $source ]; then
echo "Error with $source!"
echo "Directory either does not exist, or you do not have proper permissions."
exit 2
if [ -f $EXCLUDE_FILE ]; then
echo "Sources verified. Running rsync..."
for source in $SOURCES; do
# Create directories in $TARGET to mimick source directory hiearchy 
if [ ! -d $TARGET/$source ]; then
mkdir -p $TARGET/$source
rsync $VERBOSE --exclude=$TARGET/ $EXCLUDE -a --delete $source/ $TARGET/$source/
umount /dev/usb-harddrive
exit 0
I decided to use this script I found and modified to fit my needs, but there's one thing missing and I have no idea how to do it. When the script runs the first thing it should do, before the mounting, is checking to see if there's an USB device connected. Anyone knows how to do this?
Old 08-22-2005, 09:52 AM   #5
Registered: Jul 2002
Location: Florida
Distribution: Centos, Slackware
Posts: 260

Rep: Reputation: 30
Maybe lsusb will be your friend.

lsusb(8) Linux USB Utilities lsusb(8)

lsusb - list all USB devices

lsusb [ options ]

lsusb is a utility for displaying information about all USB buses in the system and all
devices connected to them.

To make use of all the features of this program, you need to have a Linux kernel which
supports the /proc/bus/usb interface (e.g., Linux kernel 2.3.15 or newer).


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
What backup script do you use? buldir Linux - Software 1 04-12-2005 02:57 PM
Need a backup script enygma Linux - General 5 11-04-2004 03:49 PM
Script Backup Buto Linux - General 2 10-18-2004 05:56 PM
help with backup script dennis_89 Linux - Networking 2 06-29-2004 09:47 AM
Backup Script imsajjadali Linux - General 7 01-28-2004 03:30 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:32 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration