Sitemap

Automatically Backup a MongoDB Database to DropBox using Github action

2 min readMay 30, 2021

--

Press enter or click to view image in full size
https://thetechdarts.com/wp-content/uploads/2021/04/PicsArt_04-08-07.21.39-scaled.jpg

A backup of a database is a way of protecting and restoring the data. We will see how we can take a backup from MongoDB and store the backup to dropbox.

First of all, we shall create a file named sync.sh in /scripts directory. Then we shall write our shell script to take backup and upload it to DropBox.

Now it’s time to set up GitHub action. We have to create a .gihub/workflows directory in our repository, to set up our GitHub action to automatically backup our database we have to create a .yml file as well. We have created backup.yml

.gihub/workflows/backup.yml

To upload the backup file to DropBox we need an API access token. After going to this URL https://www.dropbox.com/lp/developers click the Create apps button

Press enter or click to view image in full size

Then check Scoped access, App folder, and input your app name.

Press enter or click to view image in full size

After creating the app add permissions and don’t forget to click submit button.

Press enter or click to view image in full size

Before generating a token change Access token expiration Short-lived to No expiration.

Press enter or click to view image in full size

Copy this access token and MongoDB URI, then add it to GitHub secrets. https://github.com/{username}/{repository}/settings/secrets/actions

Press enter or click to view image in full size

Yay! We have done our setup. After pushing to the GitHub default branch, If everything fine we should get the backup on UTC 00:00 or by running this workflow manually from the Actions tab.

Press enter or click to view image in full size

--

--