PasswordLab Backup Guide
This guide walks you through creating both manual and automated backups of the complete PasswordLab software stack, covering everything from database dumps to configuration file preservation.
It's designed to help you recover quickly in case of failure or migrate PasswordLab to a new server without losing data or system integrity. Whether you're performing a scheduled backup or preparing for a full disaster recovery plan, these steps ensure your PasswordLab instance stays safe, consistent, and ready to restore at any time.
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
-
SSH into your server:
ssh root@your-server-ip
-
Run the database backup command:
mysqldump -u [db_username] -p [db_name] > /root/passwordlab-database-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.
-
Backup configuration file:
cp /etc/passwordlab/passwordlab.json /root/passwordlab-config-backup-$(date +%Y%m%d).json
-
Backup PasswordLab binary:
cp /usr/local/bin/passwordlab /root/passwordlab-binary-backup-$(date +%Y%m%d)
-
Backup systemd service file:
cp /etc/systemd/system/passwordlab.service /root/passwordlab-service-backup-$(date +%Y%m%d).service
-
Verify the backup: You should see at least four new files dated today. These files represent the backups of the database, software binary, configuration file, and system service file.
ls -lh /root/passwordlab-*
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 # Backup date DATE=$(date +%Y%m%d_%H%M%S) #Backup database mysqldump -u [db_username] -p'[db_password]' [db_name] > /root/passwordlab-database-backup-$DATE.sql # Backup configuration file cp /etc/passwordlab/passwordlab.json /root/passwordlab-config-backup-$DATE.json # Backup PasswordLab binary cp /usr/local/bin/passwordlab /root/passwordlab-binary-backup-$DATE # Backup systemd service file cp /etc/systemd/system/passwordlab.service /root/passwordlab-service-backup-$DATE.service # Optionally, add cleanup for old backups find /root -name "passwordlab-database-backup-*.sql" -mtime +60 -delete find /root -name "passwordlab-config-backup-*.json" -mtime +60 -delete find /root -name "passwordlab-binary-backup-*" -mtime +60 -delete find /root -name "passwordlab-service-backup-*.service" -mtime +60 -delete
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-database-backup-* user@remote-server:/path/to/backup/
scp /root/passwordlab-config-backup-* user@remote-server:/path/to/backup/
scp /root/passwordlab-binary-backup-* user@remote-server:/path/to/backup/
scp /root/passwordlab-service-backup-*.service user@remote-server:/path/to/backup/
Replace user@remote-server:/path/to/backup/ with your actual remote server details. Or use tools like rclone for cloud storage.
5. Important Backup Components
- Configuration file: /etc/passwordlab/passwordlab.json
- PasswordLab binary: /usr/local/bin/passwordlab
- Systemd service file: /etc/systemd/system/passwordlab.service
- Include these files in your regular backup process for full disaster recovery.
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.