LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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!

Notices


Reply
  Search this Thread
Old 01-20-2011, 02:07 PM   #1
beeson76
LQ Newbie
 
Registered: Sep 2008
Posts: 4

Rep: Reputation: 0
Need help with a Nightly backup to a usb device


Hello.

I need some answers to some very simple (hopefully not complex) questions I have.

I have Mandriva 2006 on a computer that I regularly backup important directories every night to a flash drive. I use Cron for my backup with scheduled backups nightly. For my script file to do the backup, there is a line that says to copy these directories to /media/sda/backup, so I figure it was copying to the sda named usb device. Well it wasn't. It is copying to the /media/sda/backup directory on my harddrive. But I would like to copy it to a usb device. How do I find out the name of my usb device that I have plugged in? And when writing the script for it would it be under the /dev directory? Thanks.
 
Old 01-20-2011, 03:38 PM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 372Reputation: 372Reputation: 372Reputation: 372
It's not complicated, but I have to ask some questions. Is the flash drive always connected to the computer? Do you swap it out with a different one each night?

Are you familiar with mounting and unmounting filesystems?
 
Old 01-20-2011, 03:53 PM   #3
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Jessie"
Posts: 6,085

Rep: Reputation: 398Reputation: 398Reputation: 398Reputation: 398
The above advice is basically good, but Mandriva 2006 is way out of date, and you should probably not be using it at all.

Please update your linux distro, because a lot has changed for the better over the last five years. You might be pleasantly surprised.
 
Old 01-20-2011, 04:06 PM   #4
beeson76
LQ Newbie
 
Registered: Sep 2008
Posts: 4

Original Poster
Rep: Reputation: 0
Thanks Dark Helmet for the reply. I think I will be switching out usb devices every once in a while for the backup. I am not really too familiar with the mounting and unmounting. If you would like to tell me more or a simple website would be nice. I certainly appreciate the help.
 
Old 01-20-2011, 06:31 PM   #5
FredGSanford
Senior Member
 
Registered: Nov 2005
Location: USA
Distribution: Mageia Cauldron - Debian Testing - Salix OS
Posts: 1,049
Blog Entries: 5

Rep: Reputation: 147Reputation: 147
Have you looked into the Control Center, Snapshot Backup Configuration tool?

As mention, it may be best to update to the latest version of Mandriva 2010.2, if possible.
 
Old 01-20-2011, 06:41 PM   #6
silvyus_06
Member
 
Registered: Oct 2010
Distribution: Ubuntu 10.04 , Linux Mint Debian Edition , Microsoft Windows 7
Posts: 390

Rep: Reputation: 50
errrm .. let me try to add something to actually give you a solution and not tell you what is better to do... (which is mainly a big problem on the linux forums)

make another cronjob script with right a few minutes before the actual backup script starts . for example , if you have only one harddrive on this computer , the usb drive *should* be /dev/sdb1(the first partition on device b,change these with your number and letters)

and if that script fails(e.g. no usb drive in the computer) put in the backup script some lines to check if /dev/sdb is mounted and if it is mounted to continue, but if not to abort the backup.

hopefully posting the script here would help the other users give you examples of the updated script .

good luck
 
Old 01-20-2011, 07:16 PM   #7
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,534

Rep: Reputation: 650Reputation: 650Reputation: 650Reputation: 650Reputation: 650Reputation: 650
This is the script I use to be sure things are backed up on the external USB drive instead of the mount directory of my hard disk.

Code:
#!/bin/bash

mount_point='/mnt/ext_daily'
echo_flag=''

# Find if the device is mounted

df -h | grep $mount_point > /dev/null
if [ $? -eq 0 ]
then
        $echo_flag rsync -ua --exclude='/mnt' --exclude='/proc' --exclude='/sys' --exclude='/vmware' / /mnt/ext_daily > /var/log/rsync_daily
        echo "mount point $mount_point exists, rsync started"
else
        echo "Error: mount point $mount_point does not exist, rsync operation skipped"
fi
What I do is ask a df and see if the mounted drive is listed. If it is not mounted it is not listed and grep returns 1. I call this script from CRON, an email is sent with the outcome of the test.

jlinkels
 
Old 01-20-2011, 08:49 PM   #8
Larry Webb
LQ Veteran
 
Registered: Jul 2006
Location: Crystal Beach, Texas
Distribution: Suse for mail +
Posts: 5,100
Blog Entries: 7

Rep: Reputation: 229Reputation: 229Reputation: 229
If you want to find the /dev/sdxx, if it will auto mount the easiest way I know is first unplugged do from terminal

cat /proc/partitions

and then plug in your usb then run again and what ever shows up different should be your drive.

If that does not work then do

fdisk -l (small L) as root with the same as above unplugged then again plugged. If it does not show in the first but does in the second means it is not mounted automatically and you will need to add it to your fstab or manually mount each time you plug.

Last edited by Larry Webb; 01-20-2011 at 08:54 PM.
 
Old 01-20-2011, 10:18 PM   #9
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 372Reputation: 372Reputation: 372Reputation: 372
Choosing whether to upgrade Mandriva or not is up to you. I'll assume that if you don't upgrade, there's a reason for it (older hardware, too much of a PITA, can't afford the downtime, etc.). What I planned to suggest works regardless.

Mounting and unmounting is pretty simple. When you plug a device into the machine, if all goes well, the kernel creates a device file. The device file is located in /dev and for a USB storage device (thumb drive, external HD, whatever), it's usually named sdX? (where X is a letter from a-z and ? is a number starting from 1). So, an example would be "/dev/sdc1."

For what you want to do, you cannot read/write files directly to the device file. You must mount it first. Mounting a device just integrates it into the filesystem. What you were doing originally would have worked as you expected had your USB device been mounted at /media/sda.

Enough talk... a practical example. There are other ways of doing this (see jlinkels' reply using df and Larry Webb's reply using /proc/partitions). Open a terminal, command line, shell, or whatever you like to call it. Plug in your USB drive. Now type:
Code:
dmesg
You'll get a whole bunch of info, but you're only interested in a small portion--should be the last bit. I just plugged in one of my own, and this is the tail end of what I got:
Code:
[964443.750096] usb 1-1: new high speed USB device using ehci_hcd and address 26
[964443.905301] usb 1-1: configuration #1 chosen from 1 choice
[964443.906204] scsi23 : SCSI emulation for USB Mass Storage devices
[964443.906400] usb-storage: device found at 26
[964443.906405] usb-storage: waiting for device to settle before scanning
[964448.900376] usb-storage: device scan complete
[964448.900974] scsi 23:0:0:0: Direct-Access     LEXAR    JUMPDRIVE ELITE  2000 PQ: 0 ANSI: 0 CCS
[964448.901929] sd 23:0:0:0: Attached scsi generic sg6 type 0
[964448.904498] sd 23:0:0:0: [sdg] 502880 512-byte logical blocks: (257 MB/245 MiB)
[964448.905299] sd 23:0:0:0: [sdg] Write Protect is off
[964448.905307] sd 23:0:0:0: [sdg] Mode Sense: 43 00 00 00
[964448.905313] sd 23:0:0:0: [sdg] Assuming drive cache: write through
[964448.908563] sd 23:0:0:0: [sdg] Assuming drive cache: write through
[964448.908675]  sdg: sdg1
[964448.960796] sd 23:0:0:0: [sdg] Assuming drive cache: write through
[964448.960907] sd 23:0:0:0: [sdg] Attached SCSI removable disk
The important stuff is highlighted in red. For me, the USB thumbdrive has been assigned two device files: /dev/sdg and /dev/sdg1. We're not concerned with the /dev/sdg device file--only /dev/sdg1 (the number represents a partition on the device--generally only one partition on a thumb drive). So now you mount it:
Code:
sudo mount -o uid=xxx,gid=yyy /dev/sdg1 /media/usb_drive
A couple things:
(1) You will need root privileges to execute mount. On Ubuntu systems, we use sudo. I'm not familiar with Mandriva. You may need to execute "su" first and enter the root password--then execute the mount command without the sudo at the beginning.

(2) Replace the "xxx" and "yyy" parts of the command with your text username and text groupname. For example, if your username is beeson76, do something like "uid=beeson76,gid=beeson76". Watch the spacing and if you don't know your default group, you can probably leave off the gid portion altogether. This option will allow your regular account to save your backup to the drive--no special permissions needed.

(3) Replace "/media/usb_drive" with whatever directory you want. It can be anything so long as the directory exists. After the mount is successful, writes to that directory will be diverted to your USB drive. Then update your command/script so that the backup is written to the same directory that you mounted the USB drive to.

When you want to remove the USB thumbdrive, execute:
Code:
sudo umount /dev/sdg1
Again, the sudo is only to get root privileges. Replace that with whatever Mandriva does by default.

Now, with all that said, there are some things that can automate the process a little bit (e.g. writing one or two udev rules to automatically mount one or more USB thumb drives to the appropriate location). If you're interested, either I or some other folks here can help you with that later. I figure this is enough to chew on at the moment.

Last edited by Dark_Helmet; 01-20-2011 at 10:25 PM.
 
  


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
USB drive not working properly, read only device? (USB key storage device) Arodef Linux - Hardware 14 01-01-2010 07:32 AM
How to force kernel to use a USB 2.0-compatible device (ehci_hcd) as a USB 1.1 device eze Linux - Hardware 0 05-16-2006 05:24 AM
help downloading nightly mysql db backup from one server to another... balzack Linux - Software 1 02-20-2006 02:08 AM
cron nightly backup to ftp server rkane Linux - Networking 2 03-04-2004 05:05 PM
HP Deskjet (USB) & CUPS & Slackware 9.1: Unable to open USB device "usb:/dev/usb/lp0&qu arnostienen Slackware 2 01-29-2004 03:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:08 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration