staging.inyokaproject.org

Automatisches Backup wenn eine bestimmte USB festplatte angeschlossen wird

Status: Ungelöst | Ubuntu-Version: Ubuntu 11.04 (Natty Narwhal)
Antworten |

olli0578

Anmeldungsdatum:
3. Januar 2012

Beiträge: Zähle...

Folgendes Problem: Ich habe einen kleinen Homeserver mit einer internen 2TB Festplatte. Diese Platte habe ich in zwei Partitionen eingeteilt. Partition 1 fürs System und Partition 2 für meine Daten. Partition 2 möchte ich nun automatisch auf eine bestimmte externe USB-Festplatte sichern, sobald sie angeschlossen wird. Habe jetzt schon ne ganze Menge Howtos ausprobiert, bekomme es aber einfach nicht hin.

Am weitesten bin ich mit folgendem link gekommen: http://bernaerts.dyndns.org/linux/54-debian-udev-backup Allerdings wird bei diesem Vorgehen zwar die Festplatte richtig erkannt und das Backup-Skript gestartet, jedoch werden die Daten nur in das lokale Verzeichnis geschrieben, in dem die externe Festplatte eigentlich eingehängt sein sollte.

Vielleicht kennt ja jemand eine bessere Lösung als den oben genannten Link, oder ein besseres Howto.

Danke Vorab.

HaCeMei Team-Icon

Anmeldungsdatum:
2. August 2010

Beiträge: 2269

Hallo, und herzlich willkommen hier im Forum, du wirst hier hoffentlich die nötige "Hilfe zur Selbsthilfe" bekommen.

Automatische Sicherungskopien auf einer externen Festplatte steure ich über rsync, ein Terminalprogramm, mit dem sich sehr genau angeben lässt, was wie und wo in ein backup geschrieben werden soll. Die gewünschte Anweisung kommt in ein Skript, das wiederum von anacron regelmäßig automatisch aufgerufen wird.

Vielleicht helfen dir diese Hinweise schon, sonst gebe ich gern ausführlichere Hinweise (Falls nicht jemand anders eine viel einfachere/ bessere Lösung hat).

Gruß, HaCeMei

Rorohiko

Avatar von Rorohiko

Anmeldungsdatum:
7. August 2007

Beiträge: 286

Hallo olli0578!

Der von Dir angegebene Link macht doch einen ordentlichen Eindruck.

Die Fragen an Dich sind:

1 - Wie hast Du denn die USB-Festplatte formatiert?

2 - Wie heißen die Daten-Verzeichnisse, die gesichert werden sollen?

Glück auf!

Rorohiko

dirkstolle

Avatar von dirkstolle

Anmeldungsdatum:
2. Mai 2008

Beiträge: Zähle...

Hi olli0578,

kannst Du uns bitte mehr Informationen geben? z. b. die Ausgabe von lsusb wenn die externe Festplatte angeschlossen ist? Und eventuell Dein Script, sowie die UDEV-Regel?

Das wäre gut, dann kann Dir sicherlich schneller geholfen werden.

Gruß Dirk

olli0578

(Themenstarter)

Anmeldungsdatum:
3. Januar 2012

Beiträge: 2

Die externe Festplatte ist als ext3 formatiert

lsusb gibt folgendes aus:

Bus 004 Device 002: ID 0471:0815 Philips (or NXP) eHome Infrared Receiver
Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 003 Device 002: ID 1267:0103 Logic3 / SpectraVideo plc G-720 Keyboard
Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
Bus 002 Device 003: ID 1058:1021 Western Digital Technologies, Inc. 
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Und nun zu meiner genauen Vorgehensweise:

1. Anmeldung per ssh am Server

2. root werden (hierfür nutze ich den Befehl "sudo su")

3. Externe Festplatte anschließen und einschalten

4. Herausfinden als welches device die Festplatte erkannt wird Hierfür nutze ich dmesg

dmesg bringt folgendes:

[32466.390150] usb 2-1: new high speed USB device using ehci_hcd and address 3
[32466.660452] Initializing USB Mass Storage driver...
[32466.661722] scsi8 : usb-storage 2-1:1.0
[32466.662241] usbcore: registered new interface driver usb-storage
[32466.662246] USB Mass Storage support registered.
[32467.664004] scsi 8:0:0:0: Direct-Access     WD       Ext HDD 1021     2021 PQ: 0 ANSI: 4
[32467.665326] sd 8:0:0:0: Attached scsi generic sg2 type 0
[32467.667161] sd 8:0:0:0: [sdb] 3907024896 512-byte logical blocks: (2.00 TB/1.81 TiB)
[32467.672354] sd 8:0:0:0: [sdb] Write Protect is off
[32467.672385] sd 8:0:0:0: [sdb] Mode Sense: 17 00 10 08
[32467.672394] sd 8:0:0:0: [sdb] Assuming drive cache: write through
[32467.679246] sd 8:0:0:0: [sdb] Assuming drive cache: write through
[32467.679313]  sdb: sdb1
[32467.699099] sd 8:0:0:0: [sdb] Assuming drive cache: write through
[32467.699125] sd 8:0:0:0: [sdb] Attached SCSI disk
[32469.070108] EXT3-fs: barriers not enabled
[32469.086325] kjournald starting.  Commit interval 5 seconds
[32469.089467] EXT3-fs (sdb1): using internal journal
[32469.089479] EXT3-fs (sdb1): mounted filesystem with ordered data mode

Somit wird die Festplatte als sdb erkannt und die Partition auf der Festplatte als sdb1.

5. Jetzt hole ich mir detaillierte Informationen zu der USB-Festplatte.

Und zwar mit folgendem Befehl:

udevadm info -a -p $(udevadm info -q path -n /dev/sdc)

Ausgabe:

Udevadm info starts with the device specified by the devpath and then
walks up the chain of parent devices. It prints for every device
found, all possible attributes in the udev rules key format.
A rule to match, can be composed by the attributes of the device
and the attributes from one single parent device.

  looking at device '/devices/pci0000:00/0000:00:04.1/usb2/2-1/2-1:1.0/host8/target8:0:0/8:0:0:0/block/sdb':
    KERNEL=="sdb"
    SUBSYSTEM=="block"
    DRIVER==""
    ATTR{range}=="16"
    ATTR{ext_range}=="256"
    ATTR{removable}=="0"
    ATTR{ro}=="0"
    ATTR{size}=="3907024896"
    ATTR{alignment_offset}=="0"
    ATTR{discard_alignment}=="0"
    ATTR{capability}=="50"
    ATTR{stat}=="     174        0     1386      200        1        0        8        0        0      200      200"
    ATTR{inflight}=="       0        0"

  looking at parent device '/devices/pci0000:00/0000:00:04.1/usb2/2-1/2-1:1.0/host8/target8:0:0/8:0:0:0':
    KERNELS=="8:0:0:0"
    SUBSYSTEMS=="scsi"
    DRIVERS=="sd"
    ATTRS{device_blocked}=="0"
    ATTRS{type}=="0"
    ATTRS{scsi_level}=="3"
    ATTRS{vendor}=="WD      "
    ATTRS{model}=="Ext HDD 1021    "
    ATTRS{rev}=="2021"
    ATTRS{state}=="running"
    ATTRS{timeout}=="30"
    ATTRS{iocounterbits}=="32"
    ATTRS{iorequest_cnt}=="0xd2"
    ATTRS{iodone_cnt}=="0xd2"
    ATTRS{ioerr_cnt}=="0xb"
    ATTRS{modalias}=="scsi:t-0x00"
    ATTRS{evt_media_change}=="0"
    ATTRS{dh_state}=="detached"
    ATTRS{queue_depth}=="1"
    ATTRS{queue_type}=="none"
    ATTRS{max_sectors}=="240"

  looking at parent device '/devices/pci0000:00/0000:00:04.1/usb2/2-1/2-1:1.0/host8/target8:0:0':
    KERNELS=="target8:0:0"
    SUBSYSTEMS=="scsi"
    DRIVERS==""

  looking at parent device '/devices/pci0000:00/0000:00:04.1/usb2/2-1/2-1:1.0/host8':
    KERNELS=="host8"
    SUBSYSTEMS=="scsi"
    DRIVERS==""

  looking at parent device '/devices/pci0000:00/0000:00:04.1/usb2/2-1/2-1:1.0':
    KERNELS=="2-1:1.0"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb-storage"
    ATTRS{bInterfaceNumber}=="00"
    ATTRS{bAlternateSetting}==" 0"
    ATTRS{bNumEndpoints}=="02"
    ATTRS{bInterfaceClass}=="08"
    ATTRS{bInterfaceSubClass}=="06"
    ATTRS{bInterfaceProtocol}=="50"
    ATTRS{modalias}=="usb:v1058p1021d2021dc00dsc00dp00ic08isc06ip50"
    ATTRS{supports_autosuspend}=="0"

  looking at parent device '/devices/pci0000:00/0000:00:04.1/usb2/2-1':
    KERNELS=="2-1"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{configuration}==""
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bmAttributes}=="c0"
    ATTRS{bMaxPower}=="  2mA"
    ATTRS{urbnum}=="667"
    ATTRS{idVendor}=="1058"
    ATTRS{idProduct}=="1021"
    ATTRS{bcdDevice}=="2021"
    ATTRS{bDeviceClass}=="00"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{speed}=="480"
    ATTRS{busnum}=="2"
    ATTRS{devnum}=="3"
    ATTRS{devpath}=="1"
    ATTRS{version}==" 2.00"
    ATTRS{maxchild}=="0"
    ATTRS{quirks}=="0x0"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{authorized}=="1"
    ATTRS{manufacturer}=="Western Digital"
    ATTRS{product}=="Ext HDD 1021"
    ATTRS{serial}=="5743415A4141323930313936"

  looking at parent device '/devices/pci0000:00/0000:00:04.1/usb2':
    KERNELS=="usb2"
    SUBSYSTEMS=="usb"
    DRIVERS=="usb"
    ATTRS{configuration}==""
    ATTRS{bNumInterfaces}==" 1"
    ATTRS{bConfigurationValue}=="1"
    ATTRS{bmAttributes}=="e0"
    ATTRS{bMaxPower}=="  0mA"
    ATTRS{urbnum}=="56"
    ATTRS{idVendor}=="1d6b"
    ATTRS{idProduct}=="0002"
    ATTRS{bcdDevice}=="0206"
    ATTRS{bDeviceClass}=="09"
    ATTRS{bDeviceSubClass}=="00"
    ATTRS{bDeviceProtocol}=="00"
    ATTRS{bNumConfigurations}=="1"
    ATTRS{bMaxPacketSize0}=="64"
    ATTRS{speed}=="480"
    ATTRS{busnum}=="2"
    ATTRS{devnum}=="1"
    ATTRS{devpath}=="0"
    ATTRS{version}==" 2.00"
    ATTRS{maxchild}=="6"
    ATTRS{quirks}=="0x0"
    ATTRS{avoid_reset_quirk}=="0"
    ATTRS{authorized}=="1"
    ATTRS{manufacturer}=="Linux 2.6.35-31-generic ehci_hcd"
    ATTRS{product}=="EHCI Host Controller"
    ATTRS{serial}=="0000:00:04.1"
    ATTRS{authorized_default}=="1"

  looking at parent device '/devices/pci0000:00/0000:00:04.1':
    KERNELS=="0000:00:04.1"
    SUBSYSTEMS=="pci"
    DRIVERS=="ehci_hcd"
    ATTRS{vendor}=="0x10de"
    ATTRS{device}=="0x077e"
    ATTRS{subsystem_vendor}=="0x1019"
    ATTRS{subsystem_device}=="0x2666"
    ATTRS{class}=="0x0c0320"
    ATTRS{irq}=="21"
    ATTRS{local_cpus}=="00000000,00000000,00000000,00000000,00000000,00000000,00000000,00000003"
    ATTRS{local_cpulist}=="0-1"
    ATTRS{modalias}=="pci:v000010DEd0000077Esv00001019sd00002666bc0Csc03i20"
    ATTRS{numa_node}=="0"
    ATTRS{dma_mask_bits}=="32"
    ATTRS{consistent_dma_mask_bits}=="32"
    ATTRS{enable}=="1"
    ATTRS{broken_parity_status}=="0"
    ATTRS{msi_bus}==""
    ATTRS{companion}==""

  looking at parent device '/devices/pci0000:00':
    KERNELS=="pci0000:00"
    SUBSYSTEMS==""
    DRIVERS==""

6. Aus diesen Informationen erstelle ich die udev Regel:

#nano /etc/udev/rules.d/50-backup.rules

Inhalt:

KERNEL=="sd?1", ACTION=="add", SUBSYSTEMS=="scsi", ATTRS{vendor}=="Western Digital", ATTRS{serial}=="5743415A4141323930313936", RUN+="/root/backup.sh %k"

7. UDEV neu starten:

#service udev reload

8. Jetzt das Backup Script erstellen:

nano /root/backup.sh

Inhalt:

#!/bin/bash
#
#-----------------------------------------------------------------------
#
# Script to backup all needed data upon USB hard disk insertion
# It is called thru UDEV with :
#  - the device name (sda1, ...) given as the first parameter
#
#-----------------------------------------------------------------------

# Log beggining of backup
/usr/bin/logger Backup - Beginning at `date`
# if needed, create the mount directory
if [ ! -d /media/backup ] ; then mkdir /media/backup ; fi

# if your backup disk is formatted in ext2 or ext3, use following line to mount the backup disk
/bin/mount -t auto /dev/ /media/backup
# or if your backup disk is formatted in FAT32, use following line to mount the backup disk
#/bin/mount -t vfat -o shortname=mixed,iocharset=utf8 /dev/ /mnt/backup

# Backup command using RSync
/usr/bin/logger Backup - Video
/usr/bin/rsync -rtv --del --modify-window=2 /Daten/Benutzer /media/backup

# You can add here some other backups ...
#/usr/bin/logger Backup - other files
#/usr/bin/rsync -rtv --del --modify-window=2 /path/to/your/files/other /mnt/backup

# force sync of files to disk before unmounting
/bin/sync

# unmount the backup disk
/bin/umount /media/backup

# Log end of backup
/usr/bin/logger Backup - End at `date`

Habe die Anleitung aus dem ersten Post genauso, wie ich hier gerade beschrieben habe durchgeführt. Nicht mehr und nicht weniger.

Trotzdem funktionert es nicht. Wo liegt mein Fehler?

dirkstolle

Avatar von dirkstolle

Anmeldungsdatum:
2. Mai 2008

Beiträge: Zähle...

Hi, wenn er nur in den lokalen erstellten Ordner sichert, ist die Festplatte nicht gemountet. Da ist der Fehler:

In Deinem Backup-Script steht doch:

/bin/mount -t auto /dev/ /media/backup

Da fehlt doch die Angabe der Partition sdb1, also muss es heißen

/bin/mount -t auto /dev/sdb1 /media/backup

liegts vielleicht daran?

und sicherlich meintest Du:

udevadm info -a -p $(udevadm info -q path -n /dev/sdb)

nicht (sdc):

udevadm info -a -p $(udevadm info -q path -n /dev/sdc)

oder?

Bitte nicht vergessen: den Thread als gelöst markieren fals dem so ist ;o)

Gruß Dirk

MichaelaK

Anmeldungsdatum:
25. Mai 2011

Beiträge: 617

Antworten |