LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices



Reply
 
Search this Thread
Old 08-19-2005, 05:24 AM   #1
raptorman
Member
 
Registered: Jul 2005
Location: Belgium
Distribution: Debian 2.6.13.2
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, 05:51 AM   #2
nixcraft
Member
 
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 http://bash.cyberciti.biz/backup/lin...ckup.bash.html 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 01:04 PM.
 
Old 08-19-2005, 07:29 AM   #3
raptorman
Member
 
Registered: Jul 2005
Location: Belgium
Distribution: Debian 2.6.13.2
Posts: 38

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

Original Poster
Rep: Reputation: 15
Code:
#!/bin/sh
mount /dev/usb-harddrive
# Author: Brice Burgess
# backup.sh -- backup to a local drive using rsync
# Directories to backup. Separate with a space. Exclude trailing slash!
SOURCES="/home"
# Directory to backup to. This is where your backup(s) will be stored.
# Exclude trailing slash!
TARGET="/mnt/usb-harddrive/backup"
# Comment out the following line to disable verbose output
VERBOSE="-v"
###########################
if [ ! -x $TARGET ]; then
echo "Backup target does not exist or you don't have permission!"
echo "Exiting..."
exit 2
fi
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
fi
done
if [ -f $EXCLUDE_FILE ]; then
EXCLUDE="--exclude-from=$EXCLUDE_FILE"
fi
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
fi
rsync $VERBOSE --exclude=$TARGET/ $EXCLUDE -a --delete $source/ $TARGET/$source/
done
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, 10:52 AM   #5
bbeers
Member
 
Registered: Jul 2002
Location: Florida
Distribution: Centos, Slackware
Posts: 260

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

<quote>
lsusb(8) Linux USB Utilities lsusb(8)

NAME
lsusb - list all USB devices

SYNOPSIS
lsusb [ options ]

DESCRIPTION
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).
...
</quote>
 
  


Reply


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 03:57 PM
Need a backup script enygma Linux - General 5 11-04-2004 04:49 PM
Script Backup Buto Linux - General 2 10-18-2004 06:56 PM
help with backup script dennis_89 Linux - Networking 2 06-29-2004 10:47 AM
Backup Script imsajjadali Linux - General 7 01-28-2004 04:30 PM


All times are GMT -5. The time now is 04:38 PM.

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