rdx_manager.sh 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. /bin/chown -R backuppc:root $BPC_DATAS_DIR 2>&1 || echo -e "[x] Error during chown"
  43. if [ -d "$BPC_DATAS_DIR/pool" ]; then
  44. echo -e "[*] RDX is already initilised, all is done :)"
  45. /etc/init.d/backuppc restart
  46. exit 1
  47. else
  48. echo -e "[x] RDX is steal empty"
  49. /bin/tar xvf $BPC_FILES -C $BPC_DATAS_DIR 2>&1 || echo -e "[x] Error during extract, check if $BPC_FILES exists"
  50. fi
  51. fi
  52. fi
  53. }
  54. if [ -e $BPC_DATAS_DIR/pool ]; then
  55. exit 1
  56. else
  57. check_rdx
  58. fi