linux_os2

restore_backup_of_partition

Aug 5th, 2023
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rexx 15.55 KB | None | 0 0
  1. #!/usr/bin/rexx
  2. /*  restore of one or more partitions  */
  3.  
  4. /*trace ?i ; nop*/
  5.  
  6. 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A rm /tmp/backup*'
  7.  
  8. ask_dir_to_backup         = '"Select a Directory to backup"'
  9. wrong_directory_mounted   = '"Verkeerde_Directory"'
  10. wrong_directory_text      = '"Een verkeerde directory is gemount op de backup-drive"'
  11. wrong_password            = '"Fout_tijdens_Mount"'
  12. wrong_password_text       = '"Is het paswoord misschien verkeerd ingegeven?"'
  13. succes                    = '"Succes!!!"'
  14. succes_text               = '"<big><big>De Backup is succesvol gelopen.</big></big>"'
  15. error_during_mkdir        = '"Fout_tijdens_mkdir"'
  16. error_during_mkdir_text   = '"Er is een fout opgetreden bij het aanmaken van de backup directory /mntbackup"'
  17. error_during_mount        = '"Fout_tijdens_mount"'
  18. error_during_mount_text   = '"Er is een fout opgetreden bij de mount van de backup directory /mntbackup"'
  19. error_during_umount       = '"Fout_tijdens_umount"'
  20. error_during_umount_text  = '"Er is een fout opgetreden bij de unmount van de verkeerde backup directory"'
  21. no_mntbackup              = '"no_/mntbackup"'
  22. no_mntbackup_text         = '"/mntbackup bestaat niet"'
  23. mix_of_mountpoints        = '"Mix of Mountpoints"'
  24. mix_of_mountpoints_text   = '"ofwel alleen de No.Mounts samen doen of de gemounte samen doen"'
  25. backupdev_missing         = '"Backup Device not Found"'
  26. backupdev_missing_text    = '"Is de Backupdisk verbonden?"'
  27. wrong_hardware_model_text = '"Verkeerde Machine"'
  28. 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A rm /tmp/backup*'
  29. 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A hostnamectl | grep "Hardware Model:" > /tmp/backupHardware_Model'
  30. backup_raid_member_UUID = ""
  31. Hardware_Model = linein('/tmp/backupHardware_Model')
  32. Hardware_Model = substr(Hardware_Model,pos(':',Hardware_Model) + 2)
  33. select
  34.   when Hardware_Model = "Alienware Area-51 R2" then do
  35.     backupdev_UUID = "50ea40b9-dd6b-4a87-836b-f6965841f279"
  36.     grubreboot = 3
  37.     end  
  38.   when Hardware_Model = "Marilou Dell" then do
  39.     backupdev_UUID = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
  40.     grubreboot = 2
  41.   end
  42.   when Hardware_Model = "HP ProBook 4510s" then do
  43.     backupdev_UUID = "e092c18f-0979-46ae-979f-409db1d08e2a"
  44.     grubreboot = 2
  45.   end
  46.   when Hardware_Model = "Z10PE-D16 WS" then do
  47.     backupdev_UUID = "54961d29-4f9e-4fe5-8e17-b6ea8864c3f3"
  48.     backup_raid_member_UUID = "a6f4693e-1554-697b-5c93-edf466ac4f07"
  49.     grubreboot = 2
  50.   end
  51.   otherwise
  52.     'echo 'date("I") time("N") wrong_hardware_model_text' >> /tmp/backup.log'
  53.     exit 15
  54. end
  55. mntbackup = "/mntbackup"
  56. backupdir = "backup_partition"
  57. backupdir = mntbackup"/"backupdir
  58. mountOK = 0
  59. 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A blkid | grep 'backupdev_UUID' > /tmp/backupuuid'
  60. returncode = RC
  61. backupdev = linein('/tmp/backupuuid')
  62. if backupdev = '' then do
  63.   if backup_raid_member_UUID \= ''
  64.     then do
  65.       'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A blkid | grep 'backup_raid_member_UUID' > /tmp/backupraidmemberuuid'
  66.       returncode = RC
  67.       if lines('/tmp/backupraidmemberuuid') = 0 then do
  68.         'DISPLAY=:1 zenity --info --title='backupdev_missing' --text='backupdev_missing_text
  69.         exit 15
  70.       end
  71.       backupraidmembers = ''
  72.       do while lines('/tmp/backupraidmemberuuid') \= 0
  73.         line = linein('/tmp/backupraidmemberuuid')
  74.         backupraidmembers = backupraidmembers substr(line,1,length(word(line,1)) -1)
  75.       end
  76.       'cat /proc/mdstat > /tmp/backupmdstat'
  77.       mdarrays = ''
  78.       do while lines('/tmp/backupmdstat') \= 0
  79.         line = linein('/tmp/backupmdstat')
  80.         if word(line,1) = "Personalities" then iterate
  81.         if word(line,2) = ":" then mdarrays = mdarrays","substr(word(line,1),3)
  82.         else iterate
  83.       end
  84.       mdarrays = substr(mdarrays,2)
  85.       interpret 'mdarray = min('mdarrays')'
  86.       if mdarray = 1 then interpret 'backupdev = max('mdarrays') + 1'
  87.                      else backupdev = mdarray -1
  88.       'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A mdadm --assemble /dev/md'backupdev backupraidmembers
  89.       backupdev = '/dev/md'backupdev':'
  90.     end
  91.   else do
  92.     'DISPLAY=:1 zenity --info --title='backupdev_missing' --text='backupdev_missing_text
  93.     exit 15
  94.   end
  95. end
  96. backupdev = substr(backupdev,6,length(word(backupdev,1)) -6)
  97. 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A mount | grep /dev/'backupdev ' > /tmp/backupmounted'
  98. do x = 0 while lines('/tmp/backupmounted') = 1
  99.   backupmounted = linein('/tmp/backupmounted')
  100. end
  101. select
  102.   when x = 0 then do
  103.     'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A mount /dev/'backupdev' 'mntbackup' >> /tmp/backupmount.txt 2>&1'
  104.     select
  105.       when RC = 0 then nop
  106.       when RC = 1 then do
  107.         'DISPLAY=:1 zenity --info --title='error_during_mount' --text='error_during_mount_text
  108.         exit 15
  109.       end  
  110.       when RC = 32 then do
  111.         'stat 'mntbackup' > /dev/null 2>&1'
  112.         if RC = 1 then do
  113.           'DISPLAY=:1 zenity --info --title='no_mntbackup' --text='no_mntbackup_text
  114.           exit 15
  115.         end
  116.       end
  117.       otherwise nop
  118.     end
  119.   end
  120.   when x = 1 then do
  121.     if mntbackup \= word(backupmounted,3) then do
  122.       'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A umount /dev/'backupdev' > /dev/null 2>&1'
  123.       if RC = \0 then do
  124.         'DISPLAY=:1 zenity --info --title='error_during_umount' --text='error_during_umount_text
  125.         exit 15
  126.       end
  127.       'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A mount /dev/'backupdev' 'mntbackup' >> /tmp/backupmount.txt 2>&1'
  128.       select
  129.         when RC = 0 then nop
  130.         when RC = 1
  131.           then do
  132.             'DISPLAY=:1 zenity --info --title='error_during_mount' --text='error_during_mount_text
  133.             exit 15
  134.           end  
  135.         when RC = 32 then nop
  136.         otherwise nop
  137.       end
  138.       mountOK = 1
  139.     end
  140.   end  
  141.   when x > 1 then do
  142.     'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A umount /dev/'backupdev' > /dev/null 2>&1'
  143.       if RC = \0 then do
  144.         'DISPLAY=:1 zenity --info --title='error_during_umount' --text='error_during_umount_text
  145.         exit 15
  146.       end
  147.       'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A mount /dev/'backupdev' 'mntbackup' >> /tmp/backupmount.txt 2>&1'
  148.       select
  149.         when RC = 0 then nop
  150.         when RC = 1
  151.           then do
  152.             'DISPLAY=:1 zenity --info --title='error_during_mount' --text='error_during_mount_text
  153.             exit 15
  154.           end  
  155.         when RC = 32 then nop
  156.         otherwise nop
  157.       end
  158.       mountOK = 1
  159.   end  
  160.   otherwise nop
  161. end
  162. 'stat 'backupdir'> /dev/null 2>&1'
  163. returncode = RC
  164. select
  165.   when returncode = 0 then nop
  166.   when returncode = 1
  167.     then do
  168.       'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A mkdir -p 'backupdir' > /dev/null 2>&1'
  169.       returncode = RC
  170.       if RC \= 0
  171.         then do
  172.           'DISPLAY=:1 zenity --info --title='error_during_mkdir' --text='error_during_mkdir_text
  173.           exit 15
  174.         end
  175.       'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A chmod 777 'backupdir' > /dev/null 2>&1'
  176.     end
  177.   when returncode = 32 then do
  178.     msgmnt = linein('/tmp/backupmount.txt')
  179.     if word(msgmnt,7) \= mntbackup"."
  180.       then do
  181.         'DISPLAY=:1 zenity --info --title='wrong_directory_mounted' --text='wrong_directory_text
  182.         exit 15
  183.       end
  184.     end
  185.   otherwise
  186.     'DISPLAY=:1 zenity --info --title='wrong_password' --text='wrong_password_text
  187.     exit 15
  188. end
  189. /***************************************************************************************************************************************************************************************************/
  190. 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A rm 'backupdir'/to*'
  191. 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A rm 'backupdir'/backup*'
  192. 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A rm 'backupdir'/catinfo*'
  193. 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A rm 'backupdir'/info*'
  194. 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A rm 'backupdir'/restore*'
  195. 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A rm 'backupdir'/uuid*'
  196. backupdevice. = ''
  197. backupdevice.0 = 0
  198. backupuuid. = ''
  199. backupuuid.0 = 0
  200. backupfstype. = ''
  201. backupfstype.0 = 0
  202. backupsize. = ''
  203. backupsize.0 = 0
  204. backupsizetype. = ''
  205. backupsizetype.0 = 0
  206. backupinfo. = ''
  207. backupinfo.0 = 0
  208. prevbackupuuid   = ''
  209. restorelin       = ''
  210. devices          = ''
  211. devicelist.      = ''
  212. devicelist.0     = 1
  213. fstypelist.      = ''
  214. fstypelist.0     = 1
  215. sizelist.        = ''
  216. sizelist.0       = 1
  217. sizetypelist.    = ''
  218. sizetypelist.0   = 1
  219. devtel = 1
  220. prevuuid = ''
  221. 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A ls 'backupdir'/*.info > 'backupdir'/backup_info_lst'
  222. do t = 1 while lines(backupdir'/backup_info_lst') = 1
  223.   informationfile = linein(backupdir'/backup_info_lst')
  224.   backupinfo.t = linein(informationfile)
  225.   backupinfo.0 = backupinfo.0 + 1
  226. end
  227. ADDRESS SYSTEM "sort" WITH INPUT STEM backupinfo. OUTPUT STEM backupinfo.
  228. do t = 1 to backupinfo.0
  229.   parse value backupinfo.t with  backupuuid.t . backupfstype.t . backupsize.t backupsizetype.t backuplabel.t
  230.   'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A blkid > /tmp/backupblkid't
  231.   do while lines('/tmp/backupblkid't)
  232.     device = linein('/tmp/backupblkid't)
  233.     if pos(backupuuid.t,device) \=0
  234.       then do
  235.         device = substr(device,6)
  236.         backupdevice.t = substr(device,1,pos(':',device) - 1)
  237.         leave
  238.       end
  239.       else backupdevice.t = 'nodev'
  240.   end
  241.   'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A mount | grep 'backupdevice.t' > /tmp/backupmounted'backupdevice.t'  2>/dev/null'
  242.   mntinfo = linein('/tmp/backupmounted'backupdevice.t)
  243.   if word(mntinfo,1) = '/dev/'backupdevice.t
  244.     then backupmountpoint.t = word(mntinfo,3)
  245.     else backupmountpoint.t = 'Not.Mounted'
  246. end
  247. do tll=1 to backupinfo.0
  248.   if backupdevice.tll = 'nodev' then iterate
  249.   if backupuuid.tll \= prevbackupuuid
  250.     then do
  251.       devicelist.devtel     = backupdevice.tll
  252.       fstypelist.devtel     = backupfstype.tll
  253.       sizelist.devtel       = backupsize.tll
  254.       sizetypelist.devtel   = backupsizetype.tll
  255.       labellist.devtel      = backuplabel.tll
  256.       mountpointlist.devtel = backupmountpoint.tll
  257.       uuidlist.devtel = backupuuid.tll
  258.       devtel = devtel + 1    
  259.       devicelist.0 = devicelist.0 + 1
  260.       prevbackupuuid   = backupuuid.tll
  261.     end
  262. end
  263. do tosortline.0 = 1 to devicelist.0 -1
  264.   sorttel = tosortline.0
  265.   tosortline.sorttel = devicelist.sorttel fstypelist.sorttel mountpointlist.sorttel labellist.sorttel sizelist.sorttel sizetypelist.sorttel uuidlist.sorttel
  266. end
  267. ADDRESS SYSTEM "sort" WITH INPUT STEM tosortline. OUTPUT STEM sortedline.
  268. if userid() \= 'marco'
  269.   then do dev = 1 to devicelist.0 -1
  270.     parse value sortedline.dev with devicelist.dev fstypelist.dev mountpointlist.dev labellist.dev sizelist.dev sizetypelist.dev uuidlist.dev
  271.     devices         = devices 'select' devicelist.dev fstypelist.dev mountpointlist.dev labellist.dev sizelist.dev sizetypelist.dev uuidlist.dev
  272.   end
  273.   else do dev = 2 to devicelist.0
  274.     parse value sortedline.dev with devicelist.dev fstypelist.dev mountpointlist.dev labellist.dev sizelist.dev sizetypelist.dev uuidlist.dev
  275.     devices         = devices 'select' devicelist.dev fstypelist.dev mountpointlist.dev labellist.dev sizelist.dev sizetypelist.dev uuidlist.dev
  276.   end
  277. 'DISPLAY=:1 zenity --list --checklist --title="Kies de Partities" --add-entry="File:" --print-column=ALL --column="select" --column="device" --column="fstype" --column="mountpoint" --column="label" --column="size" --column="sizetype" --column="uuid" 'devices' --width=660 --height=600 > 'backupdir'/infolist.txt'
  278. if RC \= 0 then return
  279. infolist = linein(backupdir'/infolist.txt')
  280. if infolist ='' then return
  281. restorelist = ''
  282. teller = 1
  283. do tel = 1 while infolist \= ''
  284.   parse value infolist with device '|'  fstype '|'  mountpoint '|'  label '|'  size '|'  sizetype '|'  uuid '|'  infolist
  285.   RC = lineout(backupdir'/uuid'tel)
  286. /*  'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A blkid > 'backupdir'/uuid'tel
  287. trace o
  288.     uuidline = ''
  289.     do while lines(backupdir'/uuid'tel)
  290.       device = linein(backupdir'/uuid'tel)
  291.       if pos(uuid,device) \= 0 then leave
  292.     end
  293. trace ?i ; nop
  294.   device = substr(word(device,1),1,length(word(device,1)) - 1)
  295.   device = substr(device,6)*/
  296.   RC = lineout(backupdir'/restore_device_info_lst')
  297.   'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A ls 'backupdir'/*'uuid'.info > 'backupdir'/restore_device_info_lst'
  298.   do t = 1 while lines(backupdir'/restore_device_info_lst') = 1
  299.     infoline = linein(backupdir'/restore_device_info_lst')
  300.     lastpos = lastpos('.',infoline) - 1
  301.     backuptime = substr(infoline,29,19)
  302.     backupfile = substr(infoline,1,lastpos)
  303.     'cat 'infoline' > 'backupdir'/catinfo.'teller
  304.     do while lines(backupdir'/catinfo.'teller)
  305.       info = linein(backupdir'/catinfo.'teller)
  306.       parse value info with uuid devicetest fstype mountpoint size sizetype label
  307.       restorelist = restorelist select backuptime device fstype label size sizetype backupfile uuid
  308.     end
  309.     teller = teller + 1
  310.   end
  311. end
  312. 'DISPLAY=:1 zenity --list --checklist --title="Kies de datums" --add-entry="File:" --print-column=ALL --column="select" --column="backuptime" --column="device" --column="fstype" --column="label" --column="size" --column="sizetype" --column="backupfile" --column="uuid" 'restorelist' --width=610 --height=600 > 'backupdir'/restorelist.txt'
  313. if RC \= 0 then return
  314. restorelist = linein(backupdir'/restorelist.txt')
  315. mounted = 0
  316. uuid.1 = ''
  317. uuid.0 = 1
  318. do tel = 1 while restorelist \= ''
  319.   parse value restorelist with backuptime '|' device '|' fstype '|' label '|' size '|' sizetype '|' backupfile '|' uuid '|' restorelist
  320.   'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A mount | grep 'device' > /dev/null  2>&1'
  321.   if RC \= 0
  322.     then do
  323.       'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A mount 'device' > 'backupdir'/'device.tel'  2>&1'
  324.       'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A blkid | grep 'uuid' > 'backupdir'/uuidmount'tel
  325.       partition = linein(backupdir'/uuidmount'tel)
  326.       partition = substr(word(partition,1),1,length(word(partition,1)) - 1)
  327.     end
  328.  
  329.   'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A mount | grep 'device' > /dev/null  2>&1'
  330.   if RC = 0
  331.      then do
  332.        mountstat = 'mounted'
  333.        mounted = 1
  334.      end
  335.      else mountstat = 'notmounted'
  336.       y =  uuid.0
  337.       do uuidcheck = 1 to y
  338.         if tel = 1
  339.           then do
  340.             uuidteller = uuid.0
  341.             prevuuid = uuid
  342.             uuid.uuidteller = uuid
  343.             uuid.0 = uuid.0 + 1
  344.             leave
  345.           end
  346.         if prevuuid = uuid
  347.           then do
  348.             'zenity --error --title "meerdere datums gelijk!!!" --width 500 --height 100 --text "Er zijnmeerder datums van dezelfde partietie geselecteerd.\n\n\n\n\n er mag maar één datum per partitie geselecteerd worden."'
  349.             exit 24
  350.           end
  351.       end
  352.       if tel \= 1
  353.         then do
  354.           uuidteller = uuid.0
  355.           uuid.uuidteller = uuid
  356.           prevuuid = uuid
  357.           uuid.uuidteller = uuid
  358.           uuid.0 = uuid.0 + 1
  359.         end
  360.   RC = lineout(backupdir'/torestorelist',uuid backupfile)
  361. end
  362. if mounted
  363.   then do
  364.     'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A grub-reboot 'grubreboot
  365.     'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A reboot'
  366.   end
  367.   else 'restore_partition'
  368.  
Add Comment
Please, Sign In to add comment