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. |
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? |
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. |
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.
|
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. |
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 |
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 jlinkels |
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. |
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 Code:
[964443.750096] usb 1-1: new high speed USB device using ehci_hcd and address 26 Code:
sudo mount -o uid=xxx,gid=yyy /dev/sdg1 /media/usb_drive (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 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. |
All times are GMT -5. The time now is 06:12 PM. |