Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/rexx
- /* restore of one or more partitions */
- /*trace ?i ; nop*/
- 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A rm /tmp/backup*'
- ask_dir_to_backup = '"Select a Directory to backup"'
- wrong_directory_mounted = '"Verkeerde_Directory"'
- wrong_directory_text = '"Een verkeerde directory is gemount op de backup-drive"'
- wrong_password = '"Fout_tijdens_Mount"'
- wrong_password_text = '"Is het paswoord misschien verkeerd ingegeven?"'
- succes = '"Succes!!!"'
- succes_text = '"<big><big>De Backup is succesvol gelopen.</big></big>"'
- error_during_mkdir = '"Fout_tijdens_mkdir"'
- error_during_mkdir_text = '"Er is een fout opgetreden bij het aanmaken van de backup directory /mntbackup"'
- error_during_mount = '"Fout_tijdens_mount"'
- error_during_mount_text = '"Er is een fout opgetreden bij de mount van de backup directory /mntbackup"'
- error_during_umount = '"Fout_tijdens_umount"'
- error_during_umount_text = '"Er is een fout opgetreden bij de unmount van de verkeerde backup directory"'
- no_mntbackup = '"no_/mntbackup"'
- no_mntbackup_text = '"/mntbackup bestaat niet"'
- mix_of_mountpoints = '"Mix of Mountpoints"'
- mix_of_mountpoints_text = '"ofwel alleen de No.Mounts samen doen of de gemounte samen doen"'
- backupdev_missing = '"Backup Device not Found"'
- backupdev_missing_text = '"Is de Backupdisk verbonden?"'
- wrong_hardware_model_text = '"Verkeerde Machine"'
- 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A rm /tmp/backup*'
- 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A hostnamectl | grep "Hardware Model:" > /tmp/backupHardware_Model'
- backup_raid_member_UUID = ""
- Hardware_Model = linein('/tmp/backupHardware_Model')
- Hardware_Model = substr(Hardware_Model,pos(':',Hardware_Model) + 2)
- select
- when Hardware_Model = "Alienware Area-51 R2" then do
- backupdev_UUID = "50ea40b9-dd6b-4a87-836b-f6965841f279"
- grubreboot = 3
- end
- when Hardware_Model = "Marilou Dell" then do
- backupdev_UUID = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
- grubreboot = 2
- end
- when Hardware_Model = "HP ProBook 4510s" then do
- backupdev_UUID = "e092c18f-0979-46ae-979f-409db1d08e2a"
- grubreboot = 2
- end
- when Hardware_Model = "Z10PE-D16 WS" then do
- backupdev_UUID = "54961d29-4f9e-4fe5-8e17-b6ea8864c3f3"
- backup_raid_member_UUID = "a6f4693e-1554-697b-5c93-edf466ac4f07"
- grubreboot = 2
- end
- otherwise
- 'echo 'date("I") time("N") wrong_hardware_model_text' >> /tmp/backup.log'
- exit 15
- end
- mntbackup = "/mntbackup"
- backupdir = "backup_partition"
- backupdir = mntbackup"/"backupdir
- mountOK = 0
- 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A blkid | grep 'backupdev_UUID' > /tmp/backupuuid'
- returncode = RC
- backupdev = linein('/tmp/backupuuid')
- if backupdev = '' then do
- if backup_raid_member_UUID \= ''
- then do
- 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A blkid | grep 'backup_raid_member_UUID' > /tmp/backupraidmemberuuid'
- returncode = RC
- if lines('/tmp/backupraidmemberuuid') = 0 then do
- 'DISPLAY=:1 zenity --info --title='backupdev_missing' --text='backupdev_missing_text
- exit 15
- end
- backupraidmembers = ''
- do while lines('/tmp/backupraidmemberuuid') \= 0
- line = linein('/tmp/backupraidmemberuuid')
- backupraidmembers = backupraidmembers substr(line,1,length(word(line,1)) -1)
- end
- 'cat /proc/mdstat > /tmp/backupmdstat'
- mdarrays = ''
- do while lines('/tmp/backupmdstat') \= 0
- line = linein('/tmp/backupmdstat')
- if word(line,1) = "Personalities" then iterate
- if word(line,2) = ":" then mdarrays = mdarrays","substr(word(line,1),3)
- else iterate
- end
- mdarrays = substr(mdarrays,2)
- interpret 'mdarray = min('mdarrays')'
- if mdarray = 1 then interpret 'backupdev = max('mdarrays') + 1'
- else backupdev = mdarray -1
- 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A mdadm --assemble /dev/md'backupdev backupraidmembers
- backupdev = '/dev/md'backupdev':'
- end
- else do
- 'DISPLAY=:1 zenity --info --title='backupdev_missing' --text='backupdev_missing_text
- exit 15
- end
- end
- backupdev = substr(backupdev,6,length(word(backupdev,1)) -6)
- 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A mount | grep /dev/'backupdev ' > /tmp/backupmounted'
- do x = 0 while lines('/tmp/backupmounted') = 1
- backupmounted = linein('/tmp/backupmounted')
- end
- select
- when x = 0 then do
- 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A mount /dev/'backupdev' 'mntbackup' >> /tmp/backupmount.txt 2>&1'
- select
- when RC = 0 then nop
- when RC = 1 then do
- 'DISPLAY=:1 zenity --info --title='error_during_mount' --text='error_during_mount_text
- exit 15
- end
- when RC = 32 then do
- 'stat 'mntbackup' > /dev/null 2>&1'
- if RC = 1 then do
- 'DISPLAY=:1 zenity --info --title='no_mntbackup' --text='no_mntbackup_text
- exit 15
- end
- end
- otherwise nop
- end
- end
- when x = 1 then do
- if mntbackup \= word(backupmounted,3) then do
- 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A umount /dev/'backupdev' > /dev/null 2>&1'
- if RC = \0 then do
- 'DISPLAY=:1 zenity --info --title='error_during_umount' --text='error_during_umount_text
- exit 15
- end
- 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A mount /dev/'backupdev' 'mntbackup' >> /tmp/backupmount.txt 2>&1'
- select
- when RC = 0 then nop
- when RC = 1
- then do
- 'DISPLAY=:1 zenity --info --title='error_during_mount' --text='error_during_mount_text
- exit 15
- end
- when RC = 32 then nop
- otherwise nop
- end
- mountOK = 1
- end
- end
- when x > 1 then do
- 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A umount /dev/'backupdev' > /dev/null 2>&1'
- if RC = \0 then do
- 'DISPLAY=:1 zenity --info --title='error_during_umount' --text='error_during_umount_text
- exit 15
- end
- 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A mount /dev/'backupdev' 'mntbackup' >> /tmp/backupmount.txt 2>&1'
- select
- when RC = 0 then nop
- when RC = 1
- then do
- 'DISPLAY=:1 zenity --info --title='error_during_mount' --text='error_during_mount_text
- exit 15
- end
- when RC = 32 then nop
- otherwise nop
- end
- mountOK = 1
- end
- otherwise nop
- end
- 'stat 'backupdir'> /dev/null 2>&1'
- returncode = RC
- select
- when returncode = 0 then nop
- when returncode = 1
- then do
- 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A mkdir -p 'backupdir' > /dev/null 2>&1'
- returncode = RC
- if RC \= 0
- then do
- 'DISPLAY=:1 zenity --info --title='error_during_mkdir' --text='error_during_mkdir_text
- exit 15
- end
- 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A chmod 777 'backupdir' > /dev/null 2>&1'
- end
- when returncode = 32 then do
- msgmnt = linein('/tmp/backupmount.txt')
- if word(msgmnt,7) \= mntbackup"."
- then do
- 'DISPLAY=:1 zenity --info --title='wrong_directory_mounted' --text='wrong_directory_text
- exit 15
- end
- end
- otherwise
- 'DISPLAY=:1 zenity --info --title='wrong_password' --text='wrong_password_text
- exit 15
- end
- /***************************************************************************************************************************************************************************************************/
- 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A rm 'backupdir'/to*'
- 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A rm 'backupdir'/backup*'
- 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A rm 'backupdir'/catinfo*'
- 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A rm 'backupdir'/info*'
- 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A rm 'backupdir'/restore*'
- 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A rm 'backupdir'/uuid*'
- backupdevice. = ''
- backupdevice.0 = 0
- backupuuid. = ''
- backupuuid.0 = 0
- backupfstype. = ''
- backupfstype.0 = 0
- backupsize. = ''
- backupsize.0 = 0
- backupsizetype. = ''
- backupsizetype.0 = 0
- backupinfo. = ''
- backupinfo.0 = 0
- prevbackupuuid = ''
- restorelin = ''
- devices = ''
- devicelist. = ''
- devicelist.0 = 1
- fstypelist. = ''
- fstypelist.0 = 1
- sizelist. = ''
- sizelist.0 = 1
- sizetypelist. = ''
- sizetypelist.0 = 1
- devtel = 1
- prevuuid = ''
- 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A ls 'backupdir'/*.info > 'backupdir'/backup_info_lst'
- do t = 1 while lines(backupdir'/backup_info_lst') = 1
- informationfile = linein(backupdir'/backup_info_lst')
- backupinfo.t = linein(informationfile)
- backupinfo.0 = backupinfo.0 + 1
- end
- ADDRESS SYSTEM "sort" WITH INPUT STEM backupinfo. OUTPUT STEM backupinfo.
- do t = 1 to backupinfo.0
- parse value backupinfo.t with backupuuid.t . backupfstype.t . backupsize.t backupsizetype.t backuplabel.t
- 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A blkid > /tmp/backupblkid't
- do while lines('/tmp/backupblkid't)
- device = linein('/tmp/backupblkid't)
- if pos(backupuuid.t,device) \=0
- then do
- device = substr(device,6)
- backupdevice.t = substr(device,1,pos(':',device) - 1)
- leave
- end
- else backupdevice.t = 'nodev'
- end
- 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A mount | grep 'backupdevice.t' > /tmp/backupmounted'backupdevice.t' 2>/dev/null'
- mntinfo = linein('/tmp/backupmounted'backupdevice.t)
- if word(mntinfo,1) = '/dev/'backupdevice.t
- then backupmountpoint.t = word(mntinfo,3)
- else backupmountpoint.t = 'Not.Mounted'
- end
- do tll=1 to backupinfo.0
- if backupdevice.tll = 'nodev' then iterate
- if backupuuid.tll \= prevbackupuuid
- then do
- devicelist.devtel = backupdevice.tll
- fstypelist.devtel = backupfstype.tll
- sizelist.devtel = backupsize.tll
- sizetypelist.devtel = backupsizetype.tll
- labellist.devtel = backuplabel.tll
- mountpointlist.devtel = backupmountpoint.tll
- uuidlist.devtel = backupuuid.tll
- devtel = devtel + 1
- devicelist.0 = devicelist.0 + 1
- prevbackupuuid = backupuuid.tll
- end
- end
- do tosortline.0 = 1 to devicelist.0 -1
- sorttel = tosortline.0
- tosortline.sorttel = devicelist.sorttel fstypelist.sorttel mountpointlist.sorttel labellist.sorttel sizelist.sorttel sizetypelist.sorttel uuidlist.sorttel
- end
- ADDRESS SYSTEM "sort" WITH INPUT STEM tosortline. OUTPUT STEM sortedline.
- if userid() \= 'marco'
- then do dev = 1 to devicelist.0 -1
- parse value sortedline.dev with devicelist.dev fstypelist.dev mountpointlist.dev labellist.dev sizelist.dev sizetypelist.dev uuidlist.dev
- devices = devices 'select' devicelist.dev fstypelist.dev mountpointlist.dev labellist.dev sizelist.dev sizetypelist.dev uuidlist.dev
- end
- else do dev = 2 to devicelist.0
- parse value sortedline.dev with devicelist.dev fstypelist.dev mountpointlist.dev labellist.dev sizelist.dev sizetypelist.dev uuidlist.dev
- devices = devices 'select' devicelist.dev fstypelist.dev mountpointlist.dev labellist.dev sizelist.dev sizetypelist.dev uuidlist.dev
- end
- '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'
- if RC \= 0 then return
- infolist = linein(backupdir'/infolist.txt')
- if infolist ='' then return
- restorelist = ''
- teller = 1
- do tel = 1 while infolist \= ''
- parse value infolist with device '|' fstype '|' mountpoint '|' label '|' size '|' sizetype '|' uuid '|' infolist
- RC = lineout(backupdir'/uuid'tel)
- /* 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A blkid > 'backupdir'/uuid'tel
- trace o
- uuidline = ''
- do while lines(backupdir'/uuid'tel)
- device = linein(backupdir'/uuid'tel)
- if pos(uuid,device) \= 0 then leave
- end
- trace ?i ; nop
- device = substr(word(device,1),1,length(word(device,1)) - 1)
- device = substr(device,6)*/
- RC = lineout(backupdir'/restore_device_info_lst')
- 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A ls 'backupdir'/*'uuid'.info > 'backupdir'/restore_device_info_lst'
- do t = 1 while lines(backupdir'/restore_device_info_lst') = 1
- infoline = linein(backupdir'/restore_device_info_lst')
- lastpos = lastpos('.',infoline) - 1
- backuptime = substr(infoline,29,19)
- backupfile = substr(infoline,1,lastpos)
- 'cat 'infoline' > 'backupdir'/catinfo.'teller
- do while lines(backupdir'/catinfo.'teller)
- info = linein(backupdir'/catinfo.'teller)
- parse value info with uuid devicetest fstype mountpoint size sizetype label
- restorelist = restorelist select backuptime device fstype label size sizetype backupfile uuid
- end
- teller = teller + 1
- end
- end
- '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'
- if RC \= 0 then return
- restorelist = linein(backupdir'/restorelist.txt')
- mounted = 0
- uuid.1 = ''
- uuid.0 = 1
- do tel = 1 while restorelist \= ''
- parse value restorelist with backuptime '|' device '|' fstype '|' label '|' size '|' sizetype '|' backupfile '|' uuid '|' restorelist
- 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A mount | grep 'device' > /dev/null 2>&1'
- if RC \= 0
- then do
- 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A mount 'device' > 'backupdir'/'device.tel' 2>&1'
- 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A blkid | grep 'uuid' > 'backupdir'/uuidmount'tel
- partition = linein(backupdir'/uuidmount'tel)
- partition = substr(word(partition,1),1,length(word(partition,1)) - 1)
- end
- 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A mount | grep 'device' > /dev/null 2>&1'
- if RC = 0
- then do
- mountstat = 'mounted'
- mounted = 1
- end
- else mountstat = 'notmounted'
- y = uuid.0
- do uuidcheck = 1 to y
- if tel = 1
- then do
- uuidteller = uuid.0
- prevuuid = uuid
- uuid.uuidteller = uuid
- uuid.0 = uuid.0 + 1
- leave
- end
- if prevuuid = uuid
- then do
- '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."'
- exit 24
- end
- end
- if tel \= 1
- then do
- uuidteller = uuid.0
- uuid.uuidteller = uuid
- prevuuid = uuid
- uuid.uuidteller = uuid
- uuid.0 = uuid.0 + 1
- end
- RC = lineout(backupdir'/torestorelist',uuid backupfile)
- end
- if mounted
- then do
- 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A grub-reboot 'grubreboot
- 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A reboot'
- end
- else 'restore_partition'
Add Comment
Please, Sign In to add comment