lachiu

Backup script from unraid to ubuntu

Jul 13th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. #!/bin/bash
  2. # Made by lachiu
  3. # variables
  4.  
  5. # starting time - declaration
  6. # simply grabs the day now
  7. date=$(date +"%m-%d-%Y-%T")
  8.  
  9. # filename - declaration
  10. # you can change the name to whatever you want, I'd keep "$date.tar.bz2" (so only change "backup-")
  11. filename="backup-$date.tar.bz2"
  12.  
  13. # log file - declaration
  14. # /mnt/backup is my own raid 1 array, change "/mnt/backup/" to wherever you want the log.
  15. logfile="/mnt/backup/backup.log.txt"
  16.  
  17. # folder that needs to be backed up - declaration
  18. # again, "/mnt/Documents/" is a mounted nfs share from unraid,
  19. # fstab: https://imgur.com/a/t0dDHpU,
  20. # nfs settings in unraid: 172.16.0.253(sec=sys,rw,no_root_squash,insecure) <- ip of the ubuntu 18.04 server,
  21. # (export: yes, security: private)
  22. unsec_dir="/mnt/Documents/"
  23.  
  24. # folder where the backed up files go - declaration
  25. # again, "/mnt/backup" is the raid 1 array.
  26. sec_dir="/mnt/backup"
  27.  
  28. # folder size - declaration
  29. # checks the folder size you wish to back up.
  30. fs=$(du -s $unsec_dir | cut -f1)
  31.  
  32. # color, "clr" is clear, it clears the color. Without it the color will just continue on your terminal.
  33. lightblue=`echo -e "\e[94m"`
  34. clr=`echo -e "\e[0m"`
  35.  
  36. # response at the beginning:
  37. rant1="Computer: I'll begin the script because you asked so kindly. I started at:$lightblue$date$clr"
  38.  
  39. # response for beginning
  40. rant2="Computer: I'm compressing the $lightblue$(($fs / 1024))MB$clr that I found in $lightblue$unsec_dir$clr, I'll put the compressed file in $lightblue$sec_dir$clr"
  41.  
  42. # empty line - enter for the log
  43. enter=""
  44.  
  45. #==================================================
  46.  
  47. # beginning script:
  48. $(echo $enter >> $logfile)
  49. $(echo $rant1 >> $logfile)
  50. $(echo $rant2 >> $logfile)
  51. tar -cvjf $sec_dir/$filename $unsec_dir
  52.  
  53. # 2nd bit of variables
  54. # starting time - declaration
  55. # grabs the date again
  56. date=$(date +"%m-%d-%Y-%T")
  57.  
  58. # compressed file size - declaration
  59. # checks the file size of the compressed tar.bz2
  60. fs_compressed=$(du -s $sec_dir/$filename | cut -f1)
  61.  
  62. # quick math
  63. # calculates the difference in size of the compressed file and the folder then it transfers it to MB instead of Bytes.
  64. math_result=$(( (($fs-$fs_compressed)) / 1024 ))"MB"
  65.  
  66. # rant - response if completed
  67. rant3="Computer: I've completed the compression. You're welcome by the way. We've got feelings too you know. Saying thank you wouldn't hurt. I finished at: $lightblue$date$clr"
  68. rant4="Computer: I just wanted to let you know that you won $lightblue$math_result$clr. Again, you're welcome."
  69.  
  70. $(echo $rant3 >> $logfile)
  71. $(echo $rant4 >> $logfile)
  72.  
  73. #==================================================
  74. # credits:
  75. # filename comes from linux800.be/sysadmin/cron-crontab
  76. # pipe from folder size comes from a comment on a forum post from 2012 on superuser made by user 97396 "Matteo".
  77. # Special thanks to Plutus & kroy from Homelab's Discord for explaining and helping me fix an issue with the folder's directory not being found and helping me with the calculation of the profit from the compression.
  78. # Special thanks to HAZJ, from Homelab's Discord, for helping me out with the colors.
Add Comment
Please, Sign In to add comment