Running rm -rf on / is bad. Everyone needs a backup ‘strategy’.
Server – Ubuntu 16.04RAID 6
Storage – RAID 6, mdadm. Approximately 3Tb of data requiring backup.
“The Backup Strategy”
Running Linux means this backup problem can be solved with little more than a script…
I want the script to be run every night, copying selected folders (that are important to me) only. Setting some variables in the first part of the script to help name the files that are outputted from this script.
‘dest’ is a temporary location. Writing files here makes the encryption and upload to cloud storage much simpler.
# setting variables
I want to zip the source files. Again, it’s much easier handling 1 tar.gz file than many unzipped files. Also makes the files smaller as we’re compressing them too.
# create archive
tar cvzf $dest/$filename $srcdir
As I intend to upload my data to the ‘Cloud’ I wanted to encrypt the data first. This data is important so if it’s compromised when it’s in the cloud I want some semblance of security on it.
# encrypt backup file with OpenSSL
openssl enc -aes-256-cbc -salt -in $dest/$filename -out $dest/$encfile -k passwordhere
If for whatever reason, an upload files one night, I would like everything in the temp directory to be uploaded the following night. Uploading all files in the folder makes sense. Before the upload though I want to make sure only encrypted files are in the temp folder.
# cleaning up files unecrypted before upload (upload uses all data in folder).
Using rclone, I’m uploading the encrypted files to my OneDrive storage.
# OneDrive Cloud Upload…
/usr/sbin/rclone –config=/home/username/.rclone.conf copy /home/username/temp/ onedrive:/Backup/
And after the upload, we delete the encrypted files.
# cleaning up remaining files
# rm /home/username/temp/*.enc