Advertisement
linux_os2

restoreorbackup

Aug 5th, 2023
2,209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rexx 7.24 KB | Software | 0 0
  1. #!/usr/bin/rexx
  2. /*trace ?i ; nop*/
  3.  
  4. mntbackup      = "/mntbackup"
  5. backupdir = mntbackup"/backup_partition"
  6.  
  7. backup_raid_member_UUID = ""
  8. wrong_directory_mounted  = '"Verkeerde_Directory"'
  9. wrong_directory_text     = '"Een verkeerde directory is gemount op de backup-drive"'
  10. error_during_mkdir       = '"Fout_tijdens_mkdir"'
  11. error_during_mkdir_text  = '"Er is een fout opgetreden bij het aanmaken van de backup directory /mntbackup"'
  12. error_during_mount       = '"Fout_tijdens_mount"'
  13. error_during_mount_text  = '"Er is een fout opgetreden bij de mount van de backup directory /mntbackup"'
  14. error_during_umount      = '"Fout_tijdens_umount"'
  15. error_during_umount_text = '"Er is een fout opgetreden bij de unmount van de verkeerde backup directory"'
  16. backupdev_missing        = '"Backup Device not Found"'
  17. backupdev_missing_text   = '"Is de Backupdisk verbonden?"'
  18. partition_missing_text   = '"verkeerde partitie"'
  19. wrong_hardware_model_text = '"Verkeerde Machine"'
  20. no_totasklist_found_text = '"geen opdracht lijst gevonden"'
  21. both_totasklists_found_text = '"zowel de backup opdracht lijst en de restore lijst gevonden"'
  22. 'rm /tmp/backup* > /dev/null 2>&1'
  23. 'hostnamectl | grep "Hardware Model:" > /tmp/backupHardware_Model'
  24. if lines('/etc/hostname')
  25.   then Hardware_Model = linein('/etc/hostname')
  26.   else do
  27.     Hardware_Model = Hardware_Model = linein('/tmp/backupHardware_Model')
  28.     substr(Hardware_Model,pos(':',Hardware_Model) + 2)
  29.   end
  30. select
  31.   when Hardware_Model = "Alienware Area-51 R2" then backupdev_UUID = "50ea40b9-dd6b-4a87-836b-f6965841f279"
  32.   when Hardware_Model = "Marilou Dell"         then backupdev_UUID = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
  33.   when Hardware_Model = "HP ProBook 4510s"     then backupdev_UUID = "e092c18f-0979-46ae-979f-409db1d08e2a"
  34.   when Hardware_Model = "Z10PE-D16 WS" then do
  35.     backupdev_UUID = "54961d29-4f9e-4fe5-8e17-b6ea8864c3f3"
  36.     backup_raid_member_UUID = "a6f4693e-1554-697b-5c93-edf466ac4f07"
  37.   end
  38.   when Hardware_Model = "marc-Z10PE-D16-WS" then do
  39.     backupdev_UUID = "54961d29-4f9e-4fe5-8e17-b6ea8864c3f3"
  40.     backup_raid_member_UUID = "a6f4693e-1554-697b-5c93-edf466ac4f07"
  41.   end
  42.   otherwise
  43.     'echo 'date("I") time("N") wrong_hardware_model_text' >> /tmp/restore.log'
  44.     exit 15
  45. end
  46. 'blkid | grep 'backupdev_UUID' > /tmp/backupuuid'
  47. backupdev = linein('/tmp/backupuuid')
  48. if backupdev = '' then do
  49.   if backup_raid_member_UUID \= '' then do
  50.     'blkid | grep 'backup_raid_member_UUID' > /tmp/backupraidmemberuuid'
  51.     if lines('/tmp/backupraidmemberuuid') = 0 then do
  52.       'echo 'date("I") time("N") backupdev_missing_text' >> /tmp/restore.log'
  53.       exit 15
  54.     end
  55.     backupraidmembers = ''
  56.     do while lines('/tmp/backupraidmemberuuid') \= 0
  57.       line = linein('/tmp/backupraidmemberuuid')
  58.       backupraidmembers = backupraidmembers substr(line,1,length(word(line,1)) -1)
  59.     end
  60.     'cat /proc/mdstat > /tmp/backupmdstat'
  61.     mdarrays = ''
  62.     do while lines('/tmp/backupmdstat') \= 0
  63.       line = linein('/tmp/backupmdstat')
  64.       if word(line,1) = "Personalities" then iterate
  65.       if word(line,2) = ":" then mdarrays = mdarrays","substr(word(line,1),3)
  66.       else iterate
  67.     end
  68.     mdarrays = substr(mdarrays,2)
  69.     interpret 'mdarray = min('mdarrays')'
  70.     if mdarray = 1 then interpret 'backupdev = max('mdarrays') + 1'
  71.                    else backupdev = mdarray -1
  72.       'mdadm --assemble /dev/md'backupdev backupraidmembers
  73.       backupdev = '/dev/md'backupdev':'
  74.     end
  75.   else do
  76.     'echo 'date("I") time("N") backupdev_missing_text' >> /tmp/restore.log'
  77.     exit 15
  78.   end
  79. end
  80. backupdev = substr(backupdev,6,length(word(backupdev,1)) -6)
  81. 'mount | grep /dev/'backupdev ' > /tmp/backupmounted'
  82. do x = 0 while lines('/tmp/backupmounted') = 1
  83.   backupmounted = linein('/tmp/backupmounted')
  84. end
  85. select
  86.   when x = 0 then do
  87.     'mount /dev/'backupdev' 'mntbackup' >> /tmp/backupmount.txt 2>&1'
  88.     returncode = RC    
  89.     select
  90.       when returncode = 0 then nop
  91.       when returncode = 1
  92.         then do
  93.           'echo 'date("I") time("N") error_during_mount_text' >> /tmp/restore.log'
  94.           exit 15
  95.         end  
  96.       when returncode = 32 then nop
  97.       otherwise nop
  98.     end
  99.   end
  100.   when x = 1 then do
  101.     if mntbackup \= word(backupmounted,3)
  102.       then
  103.         do
  104.           'umount /dev/'backupdev' > /dev/null 2>&1'
  105.           if RC = \0 then do
  106.             'echo 'date("I") time("N") error_during_umount_text' >> /tmp/restore.log'
  107.             exit 15
  108.           end
  109.           'mount /dev/'backupdev' 'mntbackup' >> /tmp/backupmount.txt 2>&1'
  110.       select
  111.         when RC = 0 then nop
  112.         when RC = 1
  113.           then do
  114.             'echo 'date("I") time("N") error_during_mount_text' >> /tmp/restore.log'
  115.             exit 15
  116.           end  
  117.         when RC = 32 then nop
  118.         otherwise
  119.           'echo 'date("I") time("N") error_during_mount_text' >> /tmp/restore.log'
  120.           exit 15
  121.       end
  122.     end
  123.     mountOK = 1
  124.   end  
  125.   when x > 1 then do
  126.     'umount /dev/'backupdev' > /dev/null 2>&1'
  127.     if RC = \0 then do
  128.       'echo 'date("I") time("N") error_during_umount_text' >> /tmp/restore.log'
  129.       exit 15
  130.     end
  131.     'mount /dev/'backupdev' 'mntbackup' >> /tmp/backupmount.txt 2>&1'
  132.     select
  133.       when RC = 0 then nop
  134.       when RC = 1
  135.         then do
  136.           'echo 'date("I") time("N") error_during_mount_text' >> /tmp/restore.log'
  137.           exit 15
  138.         end  
  139.       when RC = 32 then nop
  140.       otherwise nop
  141.     end
  142.     if RC \= 0 then do
  143.         'echo 'date("I") time("N") wrong_directory_text' >> /tmp/restore.log'
  144.         'rm /tmp/backup*'
  145.         exit 15
  146.       end
  147.       else mountOK = 1
  148.   end  
  149.   otherwise nop
  150. end
  151. 'stat 'backupdir' > /dev/null 2>&1'
  152. returncode = RC
  153. msgmnt = linein('/tmp/backupmount.txt')
  154. select
  155.   when returncode = 0 then nop
  156.   when returncode = 1
  157.     then do
  158.       'mkdir -p 'backupdir' > /dev/null 2>&1'
  159.       'chmod 777 'backupdir' > /dev/null 2>&1'
  160.       if RC \= 0 then do
  161.         'echo 'date("I") time("N") error_during_mkdir_text' >> 'backupdir'/restore.log'
  162.         exit 15
  163.       end
  164.     end
  165.   when returncode = 32 then
  166.     if word(msgmnt,7) \= mntbackup"."
  167.       then do
  168.         'echo 'date("I") time("N") wrong_directory_text' >> 'backupdir'/restore.log'
  169.         exit 15
  170.       end
  171.   otherwise
  172.     'echo 'date("I") time("N") wrong_password_text' >> 'backupdir'/restore.log'
  173.     exit 15
  174. end
  175. /***************************************************************************************************************/
  176. select
  177.   when lines(backupdir'/torestorelist') = 1 & lines(backupdir'/tobackuplist')  = 1
  178.     then do
  179.      'echo 'date("I") time("N") both_totasklists_found_text' >> 'backupdir'/restoreorbackup.log'
  180.      'reboot'
  181.     end
  182.   when lines(backupdir'/torestorelist') = 1
  183.    then do
  184.      'echo 'date("I") time("N") 'torestorelist_found starting restore... >> 'backupdir'/restoreorbackup.log'
  185.      '/usr/local/bin/restore_partition'
  186.    end
  187.   when lines(backupdir'/tobackuplist')  = 1
  188.     then do
  189.       'echo 'date("I") time("N") 'tobackuplist_found starting backup... >> 'backupdir'/restoreorbackup.log'
  190.       '/usr/local/bin/backup_partition'
  191.     end
  192.   otherwise
  193.   'echo 'date("I") time("N") no_totasklist_found_text' >> 'backupdir'/restoreorbackup.log'
  194.   'reboot'
  195. end
  196. return 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement