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

  1. SSH into your server:

    ssh root@your-server-ip
  2. 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.
  3. 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.

  1. 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.

  2. Make the script executable:

    chmod +x /root/backup-passwordlab.sh
  3. 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

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:

  1. Copy the backup file to your server (if needed).

  2. Restore using:

    mysql -u [db_username] -p [db_name] < /root/passwordlab-backup-YYYYMMDD.sql

6. Best Practices

By following these steps, you can ensure your PasswordLab data is safe and recoverable in any situation.