This repository provides Bash scripts for automating the export and import of data from a MongoDB collection. The backup script organizes backups based on the current year, month, and day, while the import script prompts the user to enter the file path of the backup file for importing.
Before using the scripts, make sure to:
- Have MongoDB installed.
- Set up a MongoDB URI and store it in the
.env
file. - Create a
.env
file with the following content:
MONGODB_URI="your_mongodb_uri_here"
- Clone the repository:
git clone https://github.com/realgolf/backup-script.git
- Navigate to the script directory:
cd mongodb-backup
- Make the backup script executable:
chmod +x backup.sh
- Run the backup script:
./backup.sh
This will export data from the specified MongoDB collection, create folders for the current year, month, and day, and store the backup file with a timestamp in the format HH-MM-SS.
- Navigate to the script directory:
cd mongodb-backup
- Make the import script executable:
chmod +x import.sh
- Run the import script:
./import.sh
This will prompt you to enter the file path of the backup file, and then it will import the data into the specified MongoDB collection.
Backups are organized in the following folder structure:
backups/
|-- YEAR/
| |-- MONTH/
| |-- DAY/
| |-- HH-MM-SS.json
This project is licensed under the MIT License.