rdx_manager.sh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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_init.tar.gz"
  6. init_rdx()
  7. {
  8. echo -e "[*] Unmounting RDX "
  9. 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. mkfs.ext4 $RDX_PART 2>&1 || echo -e "[x] Error during mkfs.ext4"
  14. echo -e "[*] Mounting and extracting base files..."
  15. mount $RDX_PART $BPC_DATAS_DIR 2>&1 || echo -e "[x] Error during mounting"
  16. tar xvf $BPC_FILES -C $BPC_DATAS_DIR 2>&1 || echo -e "[x] Error during extract, check if $BPC_FILES exists"
  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. echo "[*] RDX SMART OK, mouting BackupPC filesystem"
  28. if [ -e $RDX_PART ]; then
  29. echo -e "[*] fsck $RDX_PART"
  30. /sbin/fsck -f $RDX_PART 2>&1 || echo -e "[x] Error during fsck"
  31. echo -e "[*] Mount $RDX_PART in $BPC_DATAS_DIR"
  32. /bin/mount $RDX_PART $BPC_DATAS_DIR 2>&1 || echo -e "[x] Error during mount"
  33. if [ -d "/var/lib/BackupPC/pool" ]; then
  34. echo -e "[*] RDX is already initilised, all is done :)"
  35. /etc/init.d/backuppc restart
  36. else
  37. echo -e "[x] RDX is steal empty"
  38. init_rdx
  39. fi
  40. else
  41. echo -e "[x] Device $RDX_PART not found, maybe no parted?"
  42. echo -e "[*] RDX Initialisation..."
  43. init_rdx
  44. fi
  45. fi
  46. }
  47. check_rdx