autobackup/script

Standalone Automatic MySQL database backup sent directly to your email

Maintainers

Package info

github.com/mohamed-sinani/autobackup-script

Type:project

pkg:composer/autobackup/script

Transparency log

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

dev-main 2026-07-23 15:09 UTC

This package is auto-updated.

Last update: 2026-07-23 15:09:21 UTC


README

Automatic MySQL/MariaDB backup sent to your email. Works with any app that uses MySQL/MariaDB — PHP, Python, Node.js, Java, Ruby, or anything else.

Requirements

  • PHP 7.4+
  • pdo and pdo_mysql extensions
  • Composer
  • MySQL or MariaDB
  • SMTP server (Gmail, Mailgun, SendGrid, etc.)

For Linux Servers

1. Install

Option A - Composer:

cd ~/Downloads
composer create-project autobackup/script

Option B - Git:

cd ~/Downloads
git clone https://github.com/mohamed-sinani/autobackup-script.git
cd autobackup-script
composer install

2. Configure

cp .env.example .env
nano .env

Fill in your details:

# ── Database Settings ─────────────────────────────────────────
DB_HOST=localhost
DB_PORT=3306
DB_NAME=your_database_name      # Name of the database to back up
DB_USER=root                    # Database username
DB_PASS=your_password           # Database password

# ── Email Settings (SMTP) ────────────────────────────────────
# Leave SEND_EMAIL=false to skip email (local backup only)
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USERNAME=you@gmail.com     # Your Gmail / SMTP username
SMTP_PASSWORD=your_app_password # App password (see Gmail Setup below)
SMTP_ENCRYPTION=tls
FROM_EMAIL=you@gmail.com
FROM_NAME=AutoBackup

# ── Backup Settings ──────────────────────────────────────────
BACKUP_DIR=backups              # Folder to store backups
RECIPIENT_EMAIL=you@gmail.com   # Where to send the backup
KEEP_DAYS=7                     # Delete backups older than this

# ── Options ──────────────────────────────────────────────────
SEND_EMAIL=true                 # Set to "false" for backup only, no email

3. Test

php backup.php

4. Auto Schedule (cron)

Open crontab:

crontab -e

First time? You'll see a prompt to choose an editor. Just type 1 and press Enter to select nano (the easiest option).

Add this line:

0 3 * * * /usr/bin/php ~/Downloads/autobackup-script/backup.php >> ~/Downloads/autobackup-script/backup.log 2>&1

What this does: Runs backup every day at 3:00 AM.

For Windows Servers

1. Install

Option A - Composer:

cd %USERPROFILE%\Downloads
composer create-project autobackup/script

Option B - Git:

cd %USERPROFILE%\Downloads
git clone https://github.com/mohamed-sinani/autobackup-script.git
cd autobackup-script
composer install

2. Configure

copy .env.example .env
notepad .env

Fill in your details:

# ── Database Settings ─────────────────────────────────────────
DB_HOST=localhost
DB_PORT=3306
DB_NAME=your_database_name      # Name of the database to back up
DB_USER=root                    # Database username
DB_PASS=your_password           # Database password

# ── Email Settings (SMTP) ────────────────────────────────────
# Leave SEND_EMAIL=false to skip email (local backup only)
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USERNAME=you@gmail.com     # Your Gmail / SMTP username
SMTP_PASSWORD=your_app_password # App password (see Gmail Setup below)
SMTP_ENCRYPTION=tls
FROM_EMAIL=you@gmail.com
FROM_NAME=AutoBackup

# ── Backup Settings ──────────────────────────────────────────
BACKUP_DIR=backups              # Folder to store backups
RECIPIENT_EMAIL=you@gmail.com   # Where to send the backup
KEEP_DAYS=7                     # Delete backups older than this

# ── Options ──────────────────────────────────────────────────
SEND_EMAIL=true                 # Set to "false" for backup only, no email

3. Test

php backup.php

4. Auto Schedule (Task Scheduler)

  1. Open Task Scheduler (search in Start menu)
  2. Click Create Basic Task
  3. Name: AutoBackup
  4. Trigger: Daily → set time to 3:00 AM
  5. Action: Start a program
    • Program: C:\php\php.exe (your PHP path)
    • Arguments: %USERPROFILE%\Downloads\autobackup-script\backup.php
  6. Click Finish

Commands

Command What it does
php backup.php Backup + send email
php backup.php --dry-run Backup only, skip email
php backup.php --no-email Same as dry-run

Gmail Setup

Gmail needs an App Password, not your regular password:

  1. Go to Google Account → Security
  2. Enable 2-Step Verification (required)
  3. Go to App Passwords
  4. Generate one for Mail
  5. Use that password in .env

SMTP Providers

Provider Host Port
Gmail smtp.gmail.com 587
Outlook smtp.office365.com 587
Mailgun smtp.mailgun.org 587
SendGrid smtp.sendgrid.net 587
Amazon SES email-smtp.us-east-1.amazonaws.com 587

Troubleshooting

Error Fix
vendor/autoload.php not found Run composer install
Database connection failed Check DB_* values in .env
Email sending failed Verify SMTP credentials, check port 587

License

MIT - Mohamed Sinani