Backup Bash - Backing up files by date
I want to share my small bash script that compresses my website blog source files and automatically renames the file to my desire time date format. The script will generate a tarball which will allow me to drop the file quickly in my Google Drive back up folder. This saves me time in manually zipping and renaming the file to the appropriate date.
Note, you can easily modify the script to use a zip program rather than tar.
This script will work on Ubuntu or a similar Linux distro. You could also use it on MacOS as well, but I did not test it.
Create a file called backup-blog.sh and include this file in the parent directory of your blog files.
#!/bin/bash
DATE=`date +"%Y-%m-%b-%d-%Y-%I-%M-%p"`
tar czf blog-${DATE}.tar.gz blog/
echo Backup completed at blog-${DATE}.tar.gz
The first line declares that it is a bash script, and the second line assigns the date format by Year-M-MMM-Day-Hour-Minute-AM/PM, which would output “2019-06-Jun-23-8-30-PM” based on today’s date.
The third line is the compression of the directory called blog. It will compress into a tarball file called blog-2019-06-Jun-23-8-30-PM.tar.gz.
The fourth line will print a confirmation to the terminal once the compression is complete. This line is not necessary, but I like the confirmation.
Now you can back up that file to Google Drive.
My next goal is to take the tarball and upload it to Google Drive in the same script, if possible.