rdx_manager.sh 2.0 KB

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