rdx_manager.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/bash
  2. RDX_DEVICE="/dev/sdb"
  3. RDX_PART="/dev/sdb1"
  4. BPC_DATAS_DIR="/var/lib/BackupPC"
  5. BPC_FILES="/root/RDX_BackupPC/rdx_init.tar.gz"
  6. init_rdx()
  7. {
  8. echo -e "[*] Unmounting RDX "
  9. /bin/umount $RDX_PART 2>&1 || echo -e "[x] Error unmounting RDX partition"
  10. echo -e "[*] Creating /dev/sdb1..."
  11. (echo o; echo n; echo p; echo 1; echo ; echo; echo w) | fdisk $RDX_DEVICE 2>&1 || echo -e "[x] Error during parted"
  12. echo -e "[*] Creating ext4 filesystem... (this can take severals minutes)"
  13. /sbin/mkfs.ext4 $RDX_PART 2>&1 || echo -e "[x] Error during mkfs.ext4"
  14. /sbin/partprobe $RDX_DEVICE
  15. check_rdx
  16. }
  17. check_rdx()
  18. {
  19. rdx_present=$(smartctl -A $RDX_DEVICE | grep "Current Drive Temperature" | cut -d ":" -f2 | sed -e "s/\ //g")
  20. if [ "$rdx_present" = "<notavailable>" ]; then
  21. echo -e "[x] RDX SMART <notavailable>, maybe the disk is ejected?"
  22. echo -e "[x] force unmount of $BPC_DATAS_DIR"
  23. /bin/umount -f $BPC_DATAS_DIR
  24. else
  25. /sbin/partprobe $RDX_DEVICE
  26. echo "[*] RDX SMART OK, mouting BackupPC filesystem"
  27. fs_detect=$(file -s $RDX_PART | grep "ext4" 2>&1 || echo "non")
  28. if [ "$fs_detect" = "non" ]; then
  29. echo -e "[x] Device $RDX_PART not found, maybe no parted?"
  30. echo -e "[*] RDX Initialisation..."
  31. init_rdx
  32. else
  33. echo -e "Good filesystem..."
  34. fi
  35. if [ -e $RDX_PART ]; then
  36. echo -e "[*] fsck $RDX_PART"
  37. # /sbin/fsck.ext4 -f -y $RDX_PART 2>&1 || echo -e "[x] Error during fsck"
  38. echo -e "[*] Mount $RDX_PART in $BPC_DATAS_DIR"
  39. /bin/mount $RDX_PART $BPC_DATAS_DIR 2>&1 || echo -e "[x] Error during mount"
  40. /bin/chown -R backuppc:root $BPC_DATAS_DIR 2>&1 || echo -e "[x] Error during chown"
  41. if [ -d "$BPC_DATAS_DIR/pool" ]; then
  42. echo -e "[*] RDX is already initilised, all is done :)"
  43. /etc/init.d/backuppc restart
  44. exit 1
  45. else
  46. echo -e "[x] RDX is steal empty"
  47. /bin/tar xvf $BPC_FILES -C $BPC_DATAS_DIR 2>&1 || echo -e "[x] Error during extract, check if $BPC_FILES exists"
  48. fi
  49. fi
  50. fi
  51. }
  52. if [ -e $BPC_DATAS_DIR/pool ]; then
  53. echo -e "[*] Rien à faire"
  54. exit 1
  55. else
  56. /etc/init.d/crond stop
  57. check_rdx
  58. /etc/init.d/crond start
  59. fi