Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
tuto:sauvegardes:externalisation_raid1 [04/02/2011 19:11] dani [Ajout d'une tâche cron] |
tuto:sauvegardes:externalisation_raid1 [13/09/2016 11:11] (Version actuelle) dani |
||
---|---|---|---|
Ligne 13: | Ligne 13: | ||
< | < | ||
- | fdisk /dev/sdc | + | gdisk /dev/sdc |
- | [...](création d'une partition primaire /dev/sdc1 type fd) | + | [...](création d'une partition primaire /dev/sdc1 type fd00) |
</ | </ | ||
Maintenant, nous allons créer le volume RAID /dev/md0 | Maintenant, nous allons créer le volume RAID /dev/md0 | ||
< | < | ||
- | mdadm --create /dev/md0 --level=1 --force --raid-devices=1 /dev/sdc1 | + | mdadm --create / |
</ | </ | ||
Ligne 25: | Ligne 25: | ||
< | < | ||
- | mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdc1 /dev/sdd1 | + | mdadm --create / |
</ | </ | ||
- | La suite est classique, on crée un pv sur /dev/md0, puis un vg, et enfin un lv (en laissant toujours un peu d' | + | La suite est classique, on crée un pv sur /dev/md0, puis un vg, et enfin un lv (en laissant toujours un peu d' |
===== Repérer les informations des disques d' | ===== Repérer les informations des disques d' | ||
Ligne 39: | Ligne 39: | ||
Maintenant, nous allons repérer l'ID de notre disque (ou plutôt de notre partition) | Maintenant, nous allons repérer l'ID de notre disque (ou plutôt de notre partition) | ||
- | ==== COS5 ou supérieur ==== | + | ==== EL5 ou supérieur |
< | < | ||
ll / | ll / | ||
</ | </ | ||
+ | |||
Ce qui va nous renvoyer quelque chose comme ça: | Ce qui va nous renvoyer quelque chose comme ça: | ||
+ | |||
+ | |||
< | < | ||
lrwxrwxrwx 1 root root 9 déc 7 17:31 scsi-3600605b000344d40128c7c6efd3ca27a -> ../../sda | lrwxrwxrwx 1 root root 9 déc 7 17:31 scsi-3600605b000344d40128c7c6efd3ca27a -> ../../sda | ||
Ligne 56: | Ligne 60: | ||
lrwxrwxrwx 1 root root 10 déc 8 15:24 scsi-SATA_ST31500341AS_9VS2PNS6-part1 -> ../../sdd1 | lrwxrwxrwx 1 root root 10 déc 8 15:24 scsi-SATA_ST31500341AS_9VS2PNS6-part1 -> ../../sdd1 | ||
</ | </ | ||
+ | |||
Dans notre exemple, c'est /dev/sdd1 la partition qui nous intéresse, donc son ID est **scsi-SATA_ST31500341AS_9VS2PNS6-part1** (trop facile, dire que j'ai galéré à essayer de faire ça avec des règles udev à la con ;)) | Dans notre exemple, c'est /dev/sdd1 la partition qui nous intéresse, donc son ID est **scsi-SATA_ST31500341AS_9VS2PNS6-part1** (trop facile, dire que j'ai galéré à essayer de faire ça avec des règles udev à la con ;)) | ||
- | ==== COS 4 (SME7) ==== | + | ==== EL4 (valable pour SME7) ==== |
Sous CentOS 4, il n'y a pas de / | Sous CentOS 4, il n'y a pas de / | ||
- | Il faut ajouter une règle de ce type dans **/ | + | |
+ | Il faut ajouter une règle de ce type dans **/ | ||
< | < | ||
BUS=" | BUS=" | ||
</ | </ | ||
+ | |||
Pour repérer les idProduct et idVendor, on peut utiliser: | Pour repérer les idProduct et idVendor, on peut utiliser: | ||
+ | |||
+ | |||
< | < | ||
udevinfo -a -p $(udevinfo -q path -n /dev/sdd) | grep id | udevinfo -a -p $(udevinfo -q path -n /dev/sdd) | grep id | ||
</ | </ | ||
+ | |||
qui devrait donner quelque chose du genre: | qui devrait donner quelque chose du genre: | ||
+ | |||
< | < | ||
Ligne 83: | Ligne 95: | ||
</ | </ | ||
- | ici, l' | + | |
+ | ici, l' | ||
Avec la règle udev créée précédemment, | Avec la règle udev créée précédemment, | ||
Ligne 93: | Ligne 107: | ||
<code bash> | <code bash> | ||
#!/bin/bash | #!/bin/bash | ||
+ | |||
# Read configuration | # Read configuration | ||
if [ -e / | if [ -e / | ||
- | . / | + | |
else | else | ||
- | echo " | + | |
- | exit 1 | + | exit 1 |
fi | fi | ||
- | + | ||
- | + | ||
+ | |||
# Find if one of the removable disk is present | # Find if one of the removable disk is present | ||
# The first one will be used | # The first one will be used | ||
Ligne 113: | Ligne 127: | ||
fi | fi | ||
done | done | ||
+ | |||
# Check if a lock file exists | # Check if a lock file exists | ||
# And that the removable device exists | # And that the removable device exists | ||
Ligne 131: | Ligne 145: | ||
RAID_DEVICES=$(/ | RAID_DEVICES=$(/ | ||
logger "The array $RAID has $RAID_DEVICES active member(s)" | logger "The array $RAID has $RAID_DEVICES active member(s)" | ||
+ | |||
# Grow the RAID device to include one more drive (missing for now) | # Grow the RAID device to include one more drive (missing for now) | ||
logger " | logger " | ||
- | /sbin/mdadm --grow $RAID --raid-devices=$(($RAID_DEVICES+1)) | + | /sbin/mdadm --grow $RAID --raid-devices=$(($RAID_DEVICES+1)) |
+ | if [ -e "/ | ||
+ | # Check the max_sectors_kb before adding the new drive | ||
+ | OLDSIZE=$(cat / | ||
+ | |||
+ | # Freeze the FS | ||
+ | / | ||
+ | fi | ||
+ | |||
# Add the removable device to the raid array | # Add the removable device to the raid array | ||
logger " | logger " | ||
- | /sbin/mdadm --manage $RAID --add $REMOVABLE_DEVICE | + | /sbin/mdadm --manage $RAID --add --write-mostly |
- | SYNCING=1 | + | if [ -e "/ |
+ | # Now check the new max_sectors_kb | ||
+ | NEWSIZE=$(cat / | ||
+ | REMOUNT=" | ||
+ | # max_sectors_kb has changed ? | ||
+ | if [ " | ||
+ | # We need to update the max_sectors_kb of the device backing the filesystem | ||
+ | # to prevent bio too big errors | ||
+ | FSDEV=$(basename $(readlink / | ||
+ | FSDEVSIZE=$(cat / | ||
+ | if [ $FSDEVSIZE -gt $NEWSIZE ]; then | ||
+ | cat / | ||
+ | REMOUNT=" | ||
+ | fi | ||
+ | fi | ||
+ | |||
+ | # Unfreez the FS | ||
+ | / | ||
+ | |||
+ | # Remount the FS if needed (not sure if it's really needed) | ||
+ | if [ " | ||
+ | mount -o remount $TOPDIR | ||
+ | fi | ||
+ | fi | ||
+ | |||
+ | SYNCING=1 | ||
+ | |||
# Check if the sync is still running | # Check if the sync is still running | ||
while [ $SYNCING -ne 0 ]; do | while [ $SYNCING -ne 0 ]; do | ||
Ligne 147: | Ligne 195: | ||
SYNCING=$(/ | SYNCING=$(/ | ||
done | done | ||
+ | |||
logger "RAID array $RAID is now fully synced" | logger "RAID array $RAID is now fully synced" | ||
- | + | ||
- | # Stop backuppc and wait a few seconds to be sure the fs is clean | + | if [ " |
- | logger " | + | |
- | /etc/init.d/backuppc stop | + | logger " |
- | /bin/sync | + | /sbin/service |
- | /bin/sleep 10 | + | /bin/sync |
- | + | /bin/sleep 10 | |
- | # Now we can umount the volume | + | |
- | logger " | + | # Now we can umount the volume |
- | umount $TOPDIR | + | logger " |
+ | umount $TOPDIR | ||
+ | else | ||
+ | sync; sync | ||
+ | fi | ||
+ | |||
# Mark the disk as faulty | # Mark the disk as faulty | ||
logger " | logger " | ||
/sbin/mdadm --manage $RAID --fail $REMOVABLE_DEVICE | /sbin/mdadm --manage $RAID --fail $REMOVABLE_DEVICE | ||
- | sleep 5 | + | sleep 1 |
+ | |||
# Remove it | # Remove it | ||
/sbin/mdadm --manage $RAID --remove $REMOVABLE_DEVICE | /sbin/mdadm --manage $RAID --remove $REMOVABLE_DEVICE | ||
+ | |||
# And shrink the raid array so it doesn' | # And shrink the raid array so it doesn' | ||
# Only use the force flag if $RAID_DEVICES is one | # Only use the force flag if $RAID_DEVICES is one | ||
Ligne 176: | Ligne 228: | ||
fi | fi | ||
/sbin/mdadm --grow $RAID $FORCE --raid-devices=$RAID_DEVICES | /sbin/mdadm --grow $RAID $FORCE --raid-devices=$RAID_DEVICES | ||
- | + | ||
- | # We can remount the volume | + | if [ " |
- | logger " | + | |
- | mount $TOPDIR | + | logger " |
- | + | mount $TOPDIR | |
- | # and restart BackupPC | + | |
- | logger "And BackupPC server can be restarted" | + | # and restart BackupPC |
- | /etc/init.d/backuppc start | + | logger "And BackupPC server can be restarted" |
+ | /sbin/service | ||
+ | fi | ||
+ | |||
# Send a mail | # Send a mail | ||
- | logger " | + | if [ ! -z "$MAIL_TO" |
- | if [ ! -z $MAIL_TO ]; then | + | |
- | /bin/mail -s ' | + | logger " |
+ | | ||
+ | done | ||
fi | fi | ||
+ | |||
# Now loop until the link to $REMOVABLE_DEVICE is no longer here (ie. the drive is disconnected) | # Now loop until the link to $REMOVABLE_DEVICE is no longer here (ie. the drive is disconnected) | ||
# This is to prevent the sync to start over and over | # This is to prevent the sync to start over and over | ||
Ligne 197: | Ligne 253: | ||
/bin/sleep 10 | /bin/sleep 10 | ||
done | done | ||
+ | |||
# And remove the lock | # And remove the lock | ||
logger " | logger " | ||
/bin/rm -f $LOCK | /bin/rm -f $LOCK | ||
- | |||
</ | </ | ||
Ligne 223: | Ligne 278: | ||
REMOVABLE_DEVICES[0]='/ | REMOVABLE_DEVICES[0]='/ | ||
REMOVABLE_DEVICES[1]='/ | REMOVABLE_DEVICES[1]='/ | ||
+ | |||
+ | # Set this to no if you don't want BackupPC to be stopped while the external device | ||
+ | # is removed from the RAID array | ||
+ | CLEAN_REMOVE=" | ||
# Path for the lock file | # Path for the lock file | ||
Ligne 231: | Ligne 290: | ||
# is completed | # is completed | ||
# Just comment this line to disable email notification | # Just comment this line to disable email notification | ||
+ | # You can enter several mail addresses separated by space | ||
+ | # eg: MAIL_TO=' | ||
MAIL_TO=' | MAIL_TO=' | ||
</ | </ | ||
Ligne 238: | Ligne 299: | ||
Et on place également le fichier text qui contient le corps du mail à envoyer, dans / | Et on place également le fichier text qui contient le corps du mail à envoyer, dans / | ||
< | < | ||
- | Les sauvegardes ont été copié | + | Les sauvegardes ont été copiées |
L' | L' | ||
</ | </ |