PasswordLab Database Backup Guide
Regular backups of your PasswordLab database are essential to protect against data loss due to hardware failure, accidental deletion, or security incidents. This guide explains how to perform manual and automated backups of the MariaDB database used by PasswordLab.
1. Locate Your Database Credentials
Your database credentials are stored in /root/database.txt on your server. You will need the database name, username, and password for backup operations.
2. Manual Backup Using mysqldump
SSH into your server:
ssh root@your-server-ip
Run the backup command:
mysqldump -u [db_username] -p [db_name] > /root/passwordlab-backup-$(date +%Y%m%d).sql
- Replace [db_username] and [db_name] with values from /root/database.txt.
- You will be prompted for the database password.
Verify the backup:
ls -lh /root/passwordlab-backup-*.sql
3. Automated Backup Script
You can automate daily backups with a simple script and cron job.
Create a backup script:
nano /root/backup-passwordlab.sh
Paste the following (edit with your actual credentials):
#!/bin/bash DATE=$(date +%Y%m%d_%H%M%S) mysqldump -u [db_username] -p'[db_password]' [db_name] > /root/passwordlab-backup-$DATE.sql
Replace [db_username], [db_password], and [db_name] as needed.
Make the script executable:
chmod +x /root/backup-passwordlab.sh
Schedule daily backups with cron:
crontab -e
Add this line to run the backup every day at 2:00 AM:
0 2 * * * /root/backup-passwordlab.sh
4. Offsite Backup (Recommended)
For extra safety, copy your backup files to another server or cloud storage:
scp /root/passwordlab-backup-*.sql user@remote-server:/path/to/backup/
Or use tools like rclone
for cloud storage.
5. Restoring a Backup
To restore your database from a backup:
Copy the backup file to your server (if needed).
Restore using:
mysql -u [db_username] -p [db_name] < /root/passwordlab-backup-YYYYMMDD.sql
6. Best Practices
- Test your backups regularly by restoring to a test database.
- Store backups in a secure, access-controlled location.
- Automate and monitor your backup process.
- Retain multiple backup copies for redundancy.
By following these steps, you can ensure your PasswordLab data is safe and recoverable in any situation.