pgt/backup

Simple, zero-dependency database backups to S3 for Laravel applications

Maintainers

Package info

github.com/Parsons-Green-Media/pgt-backup

pkg:composer/pgt/backup

Statistics

Installs: 18

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-05-28 13:42 UTC

This package is auto-updated.

Last update: 2026-05-28 13:44:09 UTC


README

A simple, zero-configuration Laravel package that backs up your database to S3 (or any Laravel filesystem disk) on a schedule.

  • Supports MySQL, PostgreSQL, and SQLite
  • Compresses backups with gzip — no uncompressed data written to disk
  • Configurable retention: automatically prunes old backups
  • Runs daily at 2am by default via Laravel's scheduler
  • Logs output to storage/logs/pgt-backup.log

Requirements

  • PHP 8.2+
  • Laravel 10, 11, or 12
  • mysqldump (MySQL) or pg_dump (PostgreSQL) installed on the server

Installation

composer require pgt/backup

The service provider is auto-discovered. No manual registration needed.

Configuration

Publish the config file:

php artisan vendor:publish --tag=pgt-backup-config

This creates config/pgt-backup.php. The defaults work out of the box if you have standard AWS_* environment variables set.

Environment variables

Variable Default Description
BACKUP_DISK s3 Filesystem disk to upload to
BACKUP_PATH pgt-backups Directory path within the disk (root folder by default)
BACKUP_CONNECTION (default DB connection) Database connection to back up
BACKUP_REPLACE false Overwrite today's backup on re-run (date-only filename)
BACKUP_KEEP (none) Max number of backup files to retain
BACKUP_KEEP_FOR_DAYS 30 Delete backups older than this many days
BACKUP_CRON 0 2 * * * Cron schedule (default: 2am daily)
BACKUP_TIMEZONE (app timezone) Timezone for the schedule

Both BACKUP_KEEP and BACKUP_KEEP_FOR_DAYS can be set simultaneously — a file is pruned if it violates either rule.

AWS setup

Add standard AWS credentials to your .env:

AWS_ACCESS_KEY_ID=your-key-id
AWS_SECRET_ACCESS_KEY=your-secret
AWS_DEFAULT_REGION=eu-west-2
AWS_BUCKET=your-bucket-name

Ensure your S3 bucket policy allows PutObject, GetObject, ListBucket, and DeleteObject for the credentials you provide.

Scheduler

Add Laravel's scheduler to your server cron (once — if not already done):

* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1

The package registers its own schedule automatically. No changes to app/Console/Kernel.php are needed.

To disable the automatic schedule and run manually, set BACKUP_CRON= (empty) in your .env.

Running manually

php artisan pgt:backup

Override the connection or disk at runtime:

php artisan pgt:backup --connection=mysql --disk=s3

Backup files

Backups are stored as gzip-compressed SQL files. The filename format depends on the replace setting:

# replace = false (default) — one file per run, never overwritten
pgt-backups/2026-05-28_02-00-00_backup.sql.gz

# replace = true — one file per day, re-running the same day overwrites it
pgt-backups/2026-05-28_backup.sql.gz

Old backups are pruned automatically after each successful run based on your retention settings.

Logs

Each scheduled run appends output to:

storage/logs/pgt-backup.log

License

MIT — see LICENSE.