LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   How to backup files? (https://www.linuxquestions.org/questions/linux-general-1/how-to-backup-files-788522/)

MTK358 02-11-2010 03:28 PM

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?

rweaver 02-11-2010 03:35 PM

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.

MTK358 02-11-2010 03:37 PM

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?

chrism01 02-11-2010 07:10 PM

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?

MTK358 02-11-2010 07:18 PM

Quote:

Originally Posted by chrism01 (Post 3860896)
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?

How's that gonna help when I don't know WHAT to mount (remember, I am not using a desktop environment that will mount stuff automatically)?

What is a label?

chrism01 02-11-2010 07:50 PM

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

MTK358 02-11-2010 07:54 PM

But things don't get automatically mounted on my system!

Nylex 02-13-2010 02:39 AM

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..

MTK358 02-13-2010 07:36 PM

How to use udev?

jschiwal 02-13-2010 08:58 PM

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.

trey85stang 02-13-2010 09:46 PM

Quote:

Originally Posted by MTK358 (Post 3860930)
But things don't get automatically mounted on my system!

fdisk -l, will show devices available.

Nylex 02-14-2010 02:02 AM

Quote:

Originally Posted by MTK358 (Post 3862960)
How to use udev?

Read this. For information, though, udevinfo has been replaced with udevadm now.

MTK358 02-14-2010 01:49 PM

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.

allend 02-14-2010 08:14 PM

Quote:

How's that gonna help when I don't know WHAT to mount (remember, I am not using a desktop environment that will mount stuff automatically)?
I have an entry in /etc/fstab that uses 'UUID=xxx' to specify the external drive so that the device is always mounted at the same point in the file system.
Code:

# External usb harddrive for data backups writable by user with uid=1002
UUID=D86447246447052A /mnt/extusbhd ntfs-3g noauto,rw,uid=1002 0 0

You can get the UUID of your device by looking at the output of 'ls -l /dev/disk/by-uuid' when the external drive is plugged.

MTK358 02-15-2010 07:29 AM

Quote:

Originally Posted by allend (Post 3863782)
I have an entry in /etc/fstab that uses 'UUID=xxx' to specify the external drive so that the device is always mounted at the same point in the file system.

What exactly is the UUID?

Quote:

Originally Posted by allend (Post 3863782)
Code:

# External usb harddrive for data backups writable by user with uid=1002
UUID=D86447246447052A /mnt/extusbhd ntfs-3g noauto,rw,uid=1002 0 0

You can get the UUID of your device by looking at the output of 'ls -l /dev/disk/by-uuid' when the external drive is plugged.

That doesn't look like a udev rule. Is it an fstab entry?

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.