PasswordLab Configuration & Binary Backup and Restore Guide

This guide provides clear instructions for backing up and restoring the PasswordLab configuration file (/etc/passwordlab/passwordlab.json) and the PasswordLab binary (/usr/local/bin/passwordlab). Use these steps for disaster recovery, migration, or regular maintenance.

1. Manual Backup

  1. Backup configuration file:

    cp /etc/passwordlab/passwordlab.json /root/passwordlab-config-backup-$(date +%Y%m%d).json
  2. Backup PasswordLab binary:

    cp /usr/local/bin/passwordlab /root/passwordlab-binary-backup-$(date +%Y%m%d)
  3. Backup PasswordLab Systemd Service file:

    cp /etc/systemd/system/passwordlab.service /root/passwordlab-service-backup-$(date +%Y%m%d).service
  4. Verify backups:

    ls -lh /root/passwordlab-config-backup-*
    ls -lh /root/passwordlab-binary-backup-*
    ls -lh /root/passwordlab-service-backup-*

2. Automated Backup Script

  1. Create a backup script:

    nano /root/backup-passwordlab-config-binary.sh
  2. Script contents:

  3. #!/bin/bash
    DATE=$(date +%Y%m%d_%H%M%S)
    cp /etc/passwordlab/passwordlab.json /root/passwordlab-config-backup-$DATE.json
    cp /usr/local/bin/passwordlab /root/passwordlab-binary-backup-$DATE
    cp /etc/systemd/system/passwordlab.service /root/passwordlab-service-backup-$DATE.service
    # Optional: Remove backups older than 60 days
    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-*" -mtime +60 -delete
  4. Make the script executable:

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

3. Restore Process

  1. Restore configuration file:

    mkdir -p /etc/passwordlab
    cp /root/passwordlab-config-backup-YYYYMMDD.json /etc/passwordlab/passwordlab.json
  2. Restore PasswordLab binary:

    cp /root/passwordlab-binary-backup-YYYYMMDD /usr/local/bin/passwordlab
    chown root:root /usr/local/bin/passwordlab
    chmod 755 /usr/local/bin/passwordlab
  3. Reload systemd and restart the service:

    systemctl daemon-reload
    systemctl restart passwordlab
    systemctl status passwordlab
  4. Enable the service to start on boot:

    systemctl enable passwordlab
  5. Verify restoration:

    Check service status: systemctl status passwordlab

    Check logs for errors: journalctl -u passwordlab -f

Best Practices