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"
- 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"'
- no_totasklist_found_text = '"geen opdracht lijst gevonden"'
- both_totasklists_found_text = '"zowel de backup opdracht lijst en de restore lijst gevonden"'
- 'rm /tmp/backup* > /dev/null 2>&1'
- 'hostnamectl | grep "Hardware Model:" > /tmp/backupHardware_Model'
- if lines('/etc/hostname')
- then Hardware_Model = linein('/etc/hostname')
- else do
- Hardware_Model = Hardware_Model = linein('/tmp/backupHardware_Model')
- substr(Hardware_Model,pos(':',Hardware_Model) + 2)
- end
- 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"
- backup_raid_member_UUID = "a6f4693e-1554-697b-5c93-edf466ac4f07"
- end
- when Hardware_Model = "marc-Z10PE-D16-WS" then do
- backupdev_UUID = "54961d29-4f9e-4fe5-8e17-b6ea8864c3f3"
- backup_raid_member_UUID = "a6f4693e-1554-697b-5c93-edf466ac4f07"
- end
- otherwise
- 'echo 'date("I") time("N") wrong_hardware_model_text' >> /tmp/restore.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/restore.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
- 'echo 'date("I") time("N") backupdev_missing_text' >> /tmp/restore.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/restore.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/restore.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/restore.log'
- exit 15
- end
- when RC = 32 then nop
- otherwise
- 'echo 'date("I") time("N") error_during_mount_text' >> /tmp/restore.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/restore.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/restore.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/restore.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
- 'echo 'date("I") time("N") error_during_mkdir_text' >> 'backupdir'/restore.log'
- exit 15
- end
- end
- when returncode = 32 then
- if word(msgmnt,7) \= mntbackup"."
- then do
- 'echo 'date("I") time("N") wrong_directory_text' >> 'backupdir'/restore.log'
- exit 15
- end
- otherwise
- 'echo 'date("I") time("N") wrong_password_text' >> 'backupdir'/restore.log'
- exit 15
- end
- /***************************************************************************************************************/
- select
- when lines(backupdir'/torestorelist') = 1 & lines(backupdir'/tobackuplist') = 1
- then do
- 'echo 'date("I") time("N") both_totasklists_found_text' >> 'backupdir'/restoreorbackup.log'
- 'reboot'
- end
- when lines(backupdir'/torestorelist') = 1
- then do
- 'echo 'date("I") time("N") 'torestorelist_found starting restore... >> 'backupdir'/restoreorbackup.log'
- '/usr/local/bin/restore_partition'
- end
- when lines(backupdir'/tobackuplist') = 1
- then do
- 'echo 'date("I") time("N") 'tobackuplist_found starting backup... >> 'backupdir'/restoreorbackup.log'
- '/usr/local/bin/backup_partition'
- end
- otherwise
- 'echo 'date("I") time("N") no_totasklist_found_text' >> 'backupdir'/restoreorbackup.log'
- 'reboot'
- end
- return 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement