Backup MySQL & MongoDB | Bash Shell Script | Email Reports
- SSH Key Access to Remote Server. How to setup?
- Sendgrid Account (Optional) -- Incase if you want to turn on reports emailing.
Make sure to follow the below steps while creating SSH Keys and using them. Login with username specified in Github Secrets. Generate a RSA Key-Pair:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
Add newly generated key into Authorized keys.
cd .ssh && touch authorized_keys && chmod 600 authorized_keys
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
Copy
the Private Key file content and save it or download
the Private Key file
clip < ~/.ssh/id_rsa
ssh -i ~/.ssh/id_rsa user@newserver
PKEY=id_rsa
to
PKEY=/location_of_your_privatekey
Note: Filename should start with .
&& the positions of variable should stay same refer backup.sh
file
mv .example.conf .prod_server.conf
SENDGRID_API_KEY=""
to
SENDGRID_API_KEY="your-sendgrid-api-key"
sh backup.sh
If all goes well, set it up on cron.
0 0 * * * cd /to/location/of/script && sh backup.sh | tee reports.txt # Every Night at Midnight
Cron will do remaining..
Contributions, Suggestions & Feedbacks are Most Welcome
Get in touch with me at gadadarshan[at]gmail[dot]com
That's all Folks !! Enjoy.