MongoDB backups y restauración APRENDE a dominar las copias de seguridad
Creating Backups and Restoring Databases in DB
Introduction to the Course
- The video introduces a course on database management, focusing on creating backups, restoring data, and best practices for information protection.
- Key topics include using tools like Doom and Restore for database management.
Downloading Necessary Tools
- To use Doom and Restore, users must download specific tools since they are not included with DB installations from version 4 onwards.
- The required tool is "Mongod Common L Database Tools," which can be downloaded by searching for "Deb Tools" online.
- Installation involves downloading the appropriate package for your operating system (e.g., Windows), followed by a straightforward installation process.
Configuring Environment Variables
- After installation, users need to configure environment variables by accessing system settings and creating a new variable pointing to the installation directory of the tools.
- Verification of successful installation can be done through command line checks using
Doom VersionandRestore --version.
Working with Collections
- The course utilizes a tutorial database containing two collections: clients and users. Previous videos covered user authentication setup.
- Users must authenticate before performing backup operations; this includes specifying usernames and passwords during commands.
Creating Backups
- A backup folder named "Bancut DB" is created on disk D to store backups of the tutorial database.
- Commands are executed to create backups while specifying authentication details such as username, password, and authentication database.
Handling Errors During Backup Creation
- An error occurs if the authentication database is not specified correctly; it should point to 'admin' where the user was created.
- Once corrected, backups are successfully created in designated folders containing JSON files for each collection.
Advanced Backup Options
- Users can create backups for all databases without specifying individual ones or target specific collections within a database (e.g., only backing up clients).
- This flexibility allows comprehensive or selective backup strategies based on user needs.
How to Create and Restore Backups in MongoDB
Creating a Backup for Specific Collections
- The tutorial focuses on creating a backup specifically for the "clientes" collection within the "bancus" database, while excluding the "usuarios" collection.
- A new folder named "Bancut" is created to store the backup files, confirming that only the specified collection is backed up.
- Instructions are provided on setting up a scheduled task in Windows Task Scheduler to automate daily backups of the specified collection.
- The process involves specifying parameters such as frequency (daily), program execution (cmd), and necessary arguments for running the backup command.
- Key commands include specifying username, password, authentication database ("admin"), and output directory for storing backups.
Testing Backup Functionality
- After setting up the scheduled task, it can be tested by executing it manually to ensure that backups are created successfully.
- Upon execution, confirmation is given that backups were made correctly with files appearing in the designated folder.
Restoring Backups
- To restore from a backup, users must use the "restore" command along with authentication details similar to those used during backup creation.
- The restoration process requires specifying both the target database and source file location from which data will be restored.
- Issues may arise if paths or filenames are incorrect; ensuring correct specifications is crucial for successful restoration.
Targeting Specific Collections During Restoration
- Users can choose to restore specific collections rather than entire databases. This allows flexibility based on user needs.
- When restoring only certain collections (e.g., "usuarios"), precise commands must be issued detailing which collection to restore and its corresponding file path.
Best Practices for Data Backup and Restoration
- Recommendations include storing backups securely on separate servers or cloud storage solutions rather than local machines.
- Utilizing encrypted storage options is advised to protect sensitive information during both backup and restoration processes.