Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Made by lachiu
- # variables
- # starting time - declaration
- # simply grabs the day now
- date=$(date +"%m-%d-%Y-%T")
- # filename - declaration
- # you can change the name to whatever you want, I'd keep "$date.tar.bz2" (so only change "backup-")
- filename="backup-$date.tar.bz2"
- # log file - declaration
- # /mnt/backup is my own raid 1 array, change "/mnt/backup/" to wherever you want the log.
- logfile="/mnt/backup/backup.log.txt"
- # folder that needs to be backed up - declaration
- # again, "/mnt/Documents/" is a mounted nfs share from unraid,
- # fstab: https://imgur.com/a/t0dDHpU,
- # nfs settings in unraid: 172.16.0.253(sec=sys,rw,no_root_squash,insecure) <- ip of the ubuntu 18.04 server,
- # (export: yes, security: private)
- unsec_dir="/mnt/Documents/"
- # folder where the backed up files go - declaration
- # again, "/mnt/backup" is the raid 1 array.
- sec_dir="/mnt/backup"
- # folder size - declaration
- # checks the folder size you wish to back up.
- fs=$(du -s $unsec_dir | cut -f1)
- # color, "clr" is clear, it clears the color. Without it the color will just continue on your terminal.
- lightblue=`echo -e "\e[94m"`
- clr=`echo -e "\e[0m"`
- # response at the beginning:
- rant1="Computer: I'll begin the script because you asked so kindly. I started at:$lightblue$date$clr"
- # response for beginning
- 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"
- # empty line - enter for the log
- enter=""
- #==================================================
- # beginning script:
- $(echo $enter >> $logfile)
- $(echo $rant1 >> $logfile)
- $(echo $rant2 >> $logfile)
- tar -cvjf $sec_dir/$filename $unsec_dir
- # 2nd bit of variables
- # starting time - declaration
- # grabs the date again
- date=$(date +"%m-%d-%Y-%T")
- # compressed file size - declaration
- # checks the file size of the compressed tar.bz2
- fs_compressed=$(du -s $sec_dir/$filename | cut -f1)
- # quick math
- # calculates the difference in size of the compressed file and the folder then it transfers it to MB instead of Bytes.
- math_result=$(( (($fs-$fs_compressed)) / 1024 ))"MB"
- # rant - response if completed
- 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"
- rant4="Computer: I just wanted to let you know that you won $lightblue$math_result$clr. Again, you're welcome."
- $(echo $rant3 >> $logfile)
- $(echo $rant4 >> $logfile)
- #==================================================
- # credits:
- # filename comes from linux800.be/sysadmin/cron-crontab
- # pipe from folder size comes from a comment on a forum post from 2012 on superuser made by user 97396 "Matteo".
- # 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.
- # Special thanks to HAZJ, from Homelab's Discord, for helping me out with the colors.
Add Comment
Please, Sign In to add comment