How to backup files?
I was considering using a backup program or script, but I have a problem that keeps bothering me about it: How do I know if the backup media is attached, and how to know what it's device name is?
|
The device name will remain relatively static typically (in the case of tape drives) and in the case of external devices it typically picks up the next available descriptor in the chain... even if it floats you can typically use available commands to determine what is mounted and where and if its seen or not.
If you want to give a more specific example so we're not dealing with ephemeral concepts here we could probably give you better information to answer your questions. |
I am going to backup to a USB storage device, and I noticed that they get named /dev/sd<next available letter>.
But what if I unplug it? What if I plug in various devices in a different order and the wrong device gets the backup written to? Manually I use fdisk -l to find out, but what about an automated script? |
you can see what's mounted from
cat /etc/mtab you'll have to figure out a way of checking which is the one you want; use a label? |
Quote:
What is a label? |
That file is automatically updated whenever anything is mounted; usually with the udev system that happens automatically when you plug the USB device in.
To put a label on a drive (actually partition) http://linux.about.com/od/ptn_howto/a/hwtptn07t00.htm |
But things don't get automatically mounted on my system!
|
Use udev as stated above. Doing so will let you assign a meaningful name to a specific device (using some rules). Since you'll know what that name is, you'll be able to test if that device file exists in your script and if it does, mount the device..
|
How to use udev?
|
If you know the UUID or label of the filesystem, you can simply search for it in "ls /dev/disk/by-uuid/*" or "/dev/disk/by-label/".
E.G.: ls /dev/disk/by-uuid | grep 283c3ee4-2909-4ab7-b0a5-dd289c212873 grep will return true if the pattern is found and false if not. Or simply: [ -b /dev/disk/by-uuid/283c3ee4-2909-4ab7-b0a5-dd289c212873 ]; then .... You can also use the udevinfo program to query the devices or use lshal. |
Quote:
|
Quote:
|
I have made a little test udev rule that makes a symlink called "flash" for "sdb1", but I don't really understand anything beyond that.
Mainly I want to make a symlink called "backup" or something that would be a symlink to the first partition on the correct flash drive. That would allow me to make a script that checks if the "backup" device exists, and if so, do what it has to do. |
Quote:
Code:
# External usb harddrive for data backups writable by user with uid=1002 |
Quote:
Quote:
Anyway, I don't want the drive to be mounted automatically at boot-up. I could be plugging it in and out randomly. And why does it say "ntfs-3g"? |
All times are GMT -5. The time now is 05:02 AM. |