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 = dobackup()
- 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'
- Hardware_Model = linein('/etc/hostname')
- if Hardware_Model = ''
- then do
- 'hostnamectl | grep "Hardware Model:" > /tmp/backupHardware_Model'
- Hardware_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"
- 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
- RC = dobackup()
- say "De Backup is genomen"
- return
- /*************************************************************************************************************************************************************************************************************/
- dobackup:
- reboot = 0
- time = time("N")
- do while pos(':',time) \= 0
- firstpartoftime = substr(time,1,pos(':',time)-1)
- lastpartoftime = substr(time,pos(':',time)+1)
- time = firstpartoftime'-'lastpartoftime
- end
- do while pos(':',time) \= 0
- firstpartoftime = substr(time,1,pos(':',time)-1)
- lastpartoftime = substr(time,pos(':',time)+1)
- time = firstpartoftime'-'lastpartoftime
- end
- if lines(backupdir'/tobackuplist') = 0
- then do
- rc = lineout(backupdir'/'date("I")'_'time_'backup.log','no backuplist')
- exit 15
- end
- do backupnr = 1 while lines(backupdir'/tobackuplist')
- backupline = linein(backupdir'/tobackuplist')
- if backupline = 'Reboot' then do
- reboot = 1
- leave
- end
- if backupline = 'PowerOff' then do
- reboot = 0
- leave
- end
- trace o
- partuuid = word(backupline,1)
- 'blkid | grep 'partuuid' > /tmp/backuppartuuid'backupnr
- blkidpartition = linein('/tmp/backuppartuuid'backupnr)
- partitionfstype = substr(blkidpartition,(pos('TYPE="',blkidpartition) + 6))
- partitionfstype = substr(partitionfstype,1,pos('" ',partitionfstype) - 1)
- partitiondev = word(blkidpartition,1)
- partitiondev = substr(partitiondev,1,length(partitiondev) - 1 )
- backupfile = '"'backupdir'/'date("I")'_'time'_backup_'partuuid'"'
- blkline. = ''
- blkline.0 = 0
- if userid() \= 'root'
- then 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A lsblk > /tmp/lsblk'backupnr
- else 'lsblk > /tmp/lsblk'backupnr
- do tel = 1 while lines('/tmp/lsblk'backupnr)
- lsblkline = linein('/tmp/lsblk'backupnr)
- blkline.tel = lsblkline
- blkline.0 = blkline.0 + 1
- end
- do t = 1 to blkline.0
- if pos(substr(partitiondev,6),(blkline.t)) \= 0
- then do k = 1 to t
- do j = 1 to t
- if pos('raid',(blkline.t)) = 0 & pos('disk',(blkline.t)) = 0
- then do
- t = t - 1
- iterate
- end
- else do
- if pos('raid',(blkline.t)) \= 0
- then partitiondisk = '/dev/'substr(word(blkline.t,1),pos('md',blkline.t,1))
- else partitiondisk = '/dev/'word(blkline.t,1)
- leave t
- end
- end
- end
- end
- if userid() = 'root'
- then do
- rc = lineout(backupfile'.log','backup of the partition starts')
- 'partclone.'partitionfstype' -c -L "'backupfile'.log" -s 'partitiondev' | zstd --no-progress -T4 -f -o "'backupfile'.zst"'
- if RC \= 0
- then rc = lineout(backupfile'.log','unsuccesful end')
- else do
- rc = lineout(backupfile'.log','succesfull end')
- 'echo 'backupline' > 'backupfile'.info'
- end
- end
- else do
- 'echo 'date("I") time("N") 'backup of the partition starts >> 'backupfile'.log'
- 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A partclone.'partitionfstype' -c -L "'backupfile'.log" -s 'partitiondev' | zstd --no-progress -T4 -f -o "'backupfile'.zst"'
- if RC \= 0
- then 'echo 'date("I") time("N") 'backup of the partition failed >> 'backupfile'.log'
- else do
- 'echo 'date("I") time("N") 'backup of the partition was succesfull >> 'backupfile'.log'
- 'echo 'backupline' > 'backupfile'.info'
- end
- end
- if userid() = 'root'
- then 'fdisk -l 'partitiondisk' > 'backupfile'.fdisk'
- else 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A fdisk -l 'partitiondisk' > 'backupfile'.fdisk'
- end
- if userid() = 'root'
- then do
- 'rm 'backupdir'/tobackuplist'
- if reboot
- then 'reboot'
- else 'poweroff'
- end
- else 'SUDO_ASKPASS=/usr/local/bin/backup_ask_password sudo -A rm 'backupdir'/tobackuplist'
- return 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement