📌 Bash script and Node.js TypeScript job that creates dumps of MongoDB, MySQL and PostgreSQL databases in a Linux environment, packs them and uploads to MEGA Drive cloud.
It is recommended to run this backup script for all the given databases, in a Linux environment, as a cron job.
The recommended location for the script, that will work out of the box is /home/{user}
directory in a Linux environment.
The script that backups all three databases is located in /scripts
directory and called backup.sh
.
You also have to provide proper environment variables in .env
file and use pnpm package manager.
All information about environment variables can be found in the Environment Variables
section.
- Clone repository
git clone https://github.com/jakubcieslik99/dbs-backup-script.git
ℹ️ Instructions for running script manually:
- Navigate to the
backup.sh
directory
cd dbs-backup-script/scripts
- Run the script manually
./backup.sh
ℹ️ Instructions for running script as a cron job:
-
Copy all files to the server home directory
-
Add an entry to the crontab file (e.g. silent mode, 5 AM every day)
crontab -e
0 5 * * * /full/path/to/dbs-backup-script/scripts/backup.sh >/dev/null 2>&1
- Save and exit the crontab file
⚙️ To run the script, you will need to add the following environment variables to your .env file
-
MONGO_USER
-
MONGO_PASSWORD
-
MYSQL_USER
-
MYSQL_PASSWORD
-
POSTGRES_USER
-
POSTGRES_PASSWORD
-
PROJECT_NAME
-
RETENTION_HOURS
-
MEGA_EMAIL
-
MEGA_PASSWORD
-
MEGA_USER_AGENT
( ℹ️ - sample .env config file is provided in the script directory under the name .env.sample
)
If you have any feedback, please reach out to me at ✉️ contact@jakubcieslik.com