Backing Up MongoDB Databases
Backing Up MongoDB Databases
1
• authenticationDatabase is usually admin, but can be changed if you
have a different authentication database.
4.2. Add a Backup Job For example, to schedule a daily backup at 2:00
AM, add this line:
bash
Copy code
0 2 * * * /usr/bin/mongodump --db your_database_name --out /path/to/backup/directory/$(date
+\%F) >> /path/to/logs/mongodb_backup.log 2>&1
This will:
• Run the backup every day at 2 AM.
• Save the backup in a directory named with the current date (YYYY-MM-DD
format).
• Append logs to /path/to/logs/mongodb_backup.log.
2
Make sure the paths to mongodump and your directories are correct for your
setup.