Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/rexx
- /*trace ?i ; nop*/
- mntbackup = "/mntbackup"
- backupdir = mntbackup"/backup_partition"
- if userid() \= 'root' then do
- RC = dorestore()
- return
- end
- backup_raid_member_UUID = ""
- wrong_directory_mounted = '"Verkeerde_Directory"'
- wrong_directory_text = '"Een verkeerde directory is gemount op de backup-drive"'
- 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"'
- backupdev_missing = '"Backup Device not Found"'
- backupdev_missing_text = '"Is de Backupdisk verbonden?"'
- partition_missing_text = '"verkeerde partitie"'
- wrong_hardware_model_text = '"Verkeerde Machine"'
- 'rm /tmp/backup* > /dev/null 2>&1'
- /*'hostnamectl | grep "Hardware Model:" > /tmp/backupHardware_Model'*/
- Hardware_Model = linein('/etc/hostname')
- /*Hardware_Model = substr(Hardware_Model,pos(':',Hardware_Model) + 2)*/
- select
- when Hardware_Model = "Alienware Area-51 R2" then backupdev_UUID = "50ea40b9-dd6b-4a87-836b-f6965841f279"
- when Hardware_Model = "Marilou Dell" then backupdev_UUID = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
- when Hardware_Model = "HP ProBook 4510s" then backupdev_UUID = "e092c18f-0979-46ae-979f-409db1d08e2a"
- when Hardware_Model = "Z10PE-D16 WS" then do
- backupdev_UUID = "54961d29-4f9e-4fe5-8e17-b6ea8864c3f3"
- backupdev_UUID = "05eeba2c-9ab4-4bb2-93ca-85c29bc9d852" /* test ubuntu */
- backup_raid_member_UUID = "a6f4693e-1554-697b-5c93-edf466ac4f07"
- backup_raid_member_UUID = "665499be-765f-c830-cdea-afe5343febbb" /* test ubuntu */
- end
- otherwise
- 'echo 'date("I") time("N") wrong_hardware_model_text' >> /tmp/backup.log'
- exit 15
- end
- 'blkid | grep 'backupdev_UUID' > /tmp/backupuuid'
- backupdev = linein('/tmp/backupuuid')
- if backupdev = '' then do
- if backup_raid_member_UUID \= '' then do
- 'blkid | grep 'backup_raid_member_UUID' > /tmp/backupraidmemberuuid'
- if lines('/tmp/backupraidmemberuuid') = 0 then do
- 'echo 'date("I") time("N") backupdev_missing_text' >> /tmp/backup.log'
- 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
- 'mdadm --assemble /dev/md'backupdev backupraidmembers
- backupdev = '/dev/md'backupdev':'
- end
- else do
- if userid \= "cron"
- then 'DISPLAY=:1 zenity --info --title='backupdev_missing' --text='backupdev_missing_text
- else 'echo 'date("I") time("N") backupdev_missing_text' >> /tmp/backup.log'
- exit 15
- end
- end
- backupdev = substr(backupdev,6,length(word(backupdev,1)) -6)
- '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
- 'mount /dev/'backupdev' 'mntbackup' >> /tmp/backupmount.txt 2>&1'
- returncode = RC
- select
- when returncode = 0 then nop
- when returncode = 1
- then do
- 'echo 'date("I") time("N") error_during_mount_text' >> /tmp/backup.log'
- exit 15
- end
- when returncode = 32 then nop
- otherwise nop
- end
- end
- when x = 1 then do
- if mntbackup \= word(backupmounted,3)
- then
- do
- 'umount /dev/'backupdev' > /dev/null 2>&1'
- if RC = \0 then do
- 'echo 'date("I") time("N") error_during_umount_text' >> /tmp/backup.log'
- exit 15
- end
- 'mount /dev/'backupdev' 'mntbackup' >> /tmp/backupmount.txt 2>&1'
- select
- when RC = 0 then nop
- when RC = 1
- then do
- 'echo 'date("I") time("N") error_during_mount_text' >> /tmp/backup.log'
- exit 15
- end
- when RC = 32 then nop
- otherwise
- 'echo 'date("I") time("N") error_during_mount_text' >> /tmp/backup.log'
- exit 15
- end
- end
- mountOK = 1
- end
- when x > 1 then do
- 'umount /dev/'backupdev' > /dev/null 2>&1'
- if RC = \0 then do
- 'echo 'date("I") time("N") error_during_umount_text' >> /tmp/backup.log'
- exit 15
- end
- 'mount /dev/'backupdev' 'mntbackup' >> /tmp/backupmount.txt 2>&1'
- select
- when RC = 0 then nop
- when RC = 1
- then do
- 'echo 'date("I") time("N") error_during_mount_text' >> /tmp/backup.log'
- exit 15
- end
- when RC = 32 then nop
- otherwise nop
- end
- if RC \= 0 then do
- 'echo 'date("I") time("N") wrong_directory_text' >> /tmp/backup.log'
- 'rm /tmp/backup*'
- exit 15
- end
- else mountOK = 1
- end
- otherwise nop
- end
- 'stat 'backupdir' > /dev/null 2>&1'
- returncode = RC
- msgmnt = linein('/tmp/backupmount.txt')
- select
- when returncode = 0 then nop
- when returncode = 1
- then do
- 'mkdir -p 'backupdir' > /dev/null 2>&1'
- 'chmod 777 'backupdir' > /dev/null 2>&1'
- if RC \= 0 then do
- 'DISPLAY=:1 zenity --info --title='error_during_mkdir' --text='error_during_mkdir_text
- exit 15
- end
- end
- when returncode = 32 then
- if word(msgmnt,7) \= mntbackup"."
- then do
- 'echo 'date("I") time("N") wrong_directory_text' >> 'backupdir'/backup.log'
- exit 15
- end
- otherwise
- 'echo 'date("I") time("N") wrong_password_text' >> 'backupdir'/backup.log'
- exit 15
- end
- /***************************************************************************************************************************************************************************************************/
- dorestore:
- 'rm 'backupdir'/uuid* 'backupdir'/cat* 'backupdir'/DEV* 'backupdir'/restorelist.txt 'backupdir'/infolist 'backupdir'/backup_info_list'
- if lines(backupdir'/torestorelist') = 0 then RC = lineout(backupdir'/'date("I")'_'time("N")'restore.log','no tobackuplist found')
- do r = 1 while lines(backupdir'/torestorelist')
- restoreline = linein(backupdir'/torestorelist')
- partuuid = word(restoreline,1)
- if userid() = 'root'
- then 'blkid | grep 'partuuid' > 'backupdir'/uuid'r
- else 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A blkid | grep 'partuuid' > 'backupdir'/uuid'r
- partition = linein(backupdir'/uuid'r)
- partition = substr(word(partition,1),1,length(word(partition,1)) - 1)
- restorefile = word(restoreline,2)'.zst'
- restorelog = word(restoreline,2)'.restore.log'
- if userid() = 'root'
- then do
- 'echo 'date("I") time("N") ' restore of partition starts >> 'restorelog
- 'zstdcat 'restorefile' | partclone.restore -O 'partition' -L 'restorelog
- if RC \= 0
- then RC = lineout(restorelog,date("I") time("N")' restore of partition was unsuccesfull')
- else RC = lineout(restorelog,date("I") time("N")' restore of partition was succesfull')
- end
- else do
- 'echo 'date("I") time("N") ' restore of partition starts >> 'restorelog
- 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A zstdcat 'restorefile' | sudo partclone.restore -O 'partition' -L 'restorelog
- if RC \= 0
- then 'echo 'date("I") time("N") ' restore of partition was unsuccesfull >> 'restorelog
- else 'echo 'date("I") time("N") ' restore of partition was succesfull >> 'restorelog
- end
- end
- if userid() = 'root'
- then do
- 'rm 'backupdir'/torestorelist > /dev/null &2>1'
- 'reboot'
- end
- else 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A rm 'backupdir'/torestorelist > /dev/null &2>1'
- return 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement