Jump to content
  • entries
    25
  • comments
    0
  • views
    239

Walkthrough: Setting Up BackupNinja to Back Up a Website on Linux to a Windows Machine Using SMB


Prerequisites

Before proceeding, ensure the following components are in place:

BackupNinja Installed

Verify BackupNinja is installed on your Linux server.

Command:

sudo apt update && sudo apt install backupninja
  • Common Errors & Solutions:

  • Error: "Unable to locate package backupninja"
    • Ensure your repositories are up-to-date:
      sudo apt update
    • Enable the universe repository on Ubuntu/Debian systems:
      sudo add-apt-repository universe

SMB Share Configured on the Windows Machine

  1. Create a shared folder (e.g., BackupShare).
  2. Set folder permissions to grant the Linux server access:
    • Go to Properties → Sharing → Advanced Sharing.
    • Check "Share this folder" and set permissions for a specific user.
  3. Note the share path and credentials for the Linux server.

Common Errors & Solutions:

  • Error: "Permission denied" when accessing the share
    • Double-check share permissions and ensure the user has read/write access.
    • Ensure the Windows firewall allows SMB traffic.
    • Confirm that SMBv1 is disabled on the Windows machine (use SMBv2 or SMBv3).

Database Credentials

Gather the necessary credentials for your databases (MySQL/PostgreSQL). Verify that the user has sufficient privileges to perform backups.

MySQL Privileges Check:

SHOW GRANTS FOR 'backupuser'@'localhost';

PostgreSQL Privileges Check:

psql -U postgres -c "\du"

Install cifs-utils Package on Linux

The cifs-utils package is essential for mounting SMB shares.

Command:

sudo apt install cifs-utils

Step 1: Configure the /etc/backup.d Directory

Navigate to the directory:

cd /etc/backup.d/

Step 2: Create a Configuration File for Backing Up /var/www

Create the backup task file:

sudo nano /etc/backup.d/01-var-www.rsync

Configuration Example:

[general]
when = everyday at 02:00

[rsync]
source = /var/www/
destination = //WINDOWS-MACHINE/BackupShare/www/
options = -a --delete
smbuser = windowsuser
smbpassword = windowspassword

Additional Tips:

  • Use IP address instead of hostname for reliability (e.g., //192.168.1.100/BackupShare/www/).
  • Consider using a credential file for security instead of plaintext credentials.

Credential File Method:

  1. Create the file:
    sudo nano /etc/backup.d/smb.credentials
  2. Add credentials:
    username=windowsuser
    password=windowspassword
  3. Update your backup configuration:
    smbcredentials = /etc/backup.d/smb.credential

Step 3: Create a Configuration File for Database Backups

For MySQL:

sudo nano /etc/backup.d/02-databases.mysqldump

Example Configuration:

[general]
when = everyday at 03:00

[mysqldump]
user = backupuser
password = secretpassword
host = localhost
databases = --all-databases
compress = true
destination = //WINDOWS-MACHINE/BackupShare/mysql/all-databases.sql.gz
smbuser = windowsuser
smbpassword = windowspassword

For PostgreSQL:

sudo nano /etc/backup.d/02-databases.pgsql

Example Configuration:

[general]
when = everyday at 03:00

[pg_dump]
user = postgres
host = localhost
all = yes
compress = true
destination = //WINDOWS-MACHINE/BackupShare/pgsql/all-databases.sql.gz
smbuser = windowsuser
smbpassword = windowspassword

Step 4: Verify the Backup Configuration

Run a configuration check:

sudo backupninja --check

Check Output:

  • Ensure no syntax errors or missing parameters.
  • If issues arise, check the log at /var/log/backupninja.log.

Step 5: Test the Backup Manually

sudo backupninja --run

Verify the Backup on the Windows Machine:
Check the BackupShare folder for your /var/www and database backups.

Common Errors & Solutions:

  • Error: "Permission denied"
    • Ensure the Linux server can access the share:
      sudo mount -t cifs //WINDOWS-MACHINE/BackupShare /mnt -o username=windowsuser,password=windowspassword
    • Check /var/log/syslog or /var/log/messages for SMB-related errors.

Step 6: Automate the Backup with Cron

BackupNinja automatically sets up cron jobs based on the when parameter.

Verify cron jobs:

sudo crontab -l

If necessary, restart the cron service:

sudo systemctl restart cron

Step 7: Secure the Backup Files

  1. Set Share Permissions: Restrict access to authorized users only.
  2. Encrypt Backups: Use GPG to encrypt backup files.

Example GPG Command:

gpg --encrypt --recipient 'your-email@example.com' backup-file.sql.gz

Step 8: Monitor Backup Logs

Regularly check BackupNinja logs for any errors:

tail -f /var/log/backupninja.log

Additional Enhancements:

Mount the SMB Share at Boot

Add the SMB share to /etc/fstab to automatically mount it at boot.

Example Entry in /etc/fstab:

//192.168.1.100/BackupShare /mnt/backup cifs credentials=/etc/backup.d/smb.credentials,iocharset=utf8,sec=ntlm 0 0

Security Recommendations:

  • Use SSH tunneling for database backups to enhance security.
  • Regularly rotate credentials and secure your smb.credentials file:
    sudo chmod 600 /etc/backup.d/smb.credential

0 Comments


Recommended Comments

There are no comments to display.

×
×
  • Create New...

Important Information

Terms of Use Privacy Policy Guidelines We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.