How to Backup Your Snipe-IT Database: Complete Guide for Admins
Snipe-IT leverages the spatie/laravel-backup package to generate MySQL database backups through the web interface, API, or command line, storing them securely in storage/app/backups by default.
Managing asset data in the grokability/snipe-it repository requires a reliable backup strategy. The application integrates the spatie/laravel-backup package to handle database dumps and file archives, giving administrators multiple ways to protect their inventory data. This guide explains the backup architecture, configuration files, and step-by-step methods to create and restore your Snipe-IT database.
Snipe-IT Backup Architecture
Understanding how the backup system is wired helps troubleshoot issues and customize behavior. The implementation spans configuration files, controllers, and routes.
Configuration Files
The primary configuration lives in config/backup.php, which defines what files and databases to include, retention policies, and storage disks. MySQL connection details and mysqldump options are configured in config/database.php (see line 11 comments referencing spatie backup). For remote storage like S3, disks are defined in config/filesystems.php.
Web Interface Controller
In app/Http/Controllers/SettingsController.php at line 901, the postBackups() method handles HTTP requests from the admin panel. This method validates admin permissions using Gate::allows('admin') before executing the backup command.
Routes and API Access
Web routes for the backup UI are registered in routes/web.php (lines 363-388), exposing the interface under Settings → Backups. For programmatic access, API endpoints in routes/api.php (lines 982-996) allow external tools to list, download, and trigger backups.
How to Create a Snipe-IT Database Backup
Administrators can initiate backups through three interfaces depending on their workflow.
Method 1: Web Interface (Settings → Backups)
Navigate to Settings → Backups and click the "Generate Backup" button. This POSTs to SettingsController::postBackups, which executes the underlying Artisan command. The resulting zip file appears in the backup list once complete.
Method 2: Command Line (Artisan)
For manual backups or scripting, use the Artisan command from your Snipe-IT root directory:
# Database-only backup
php artisan backup:run --only-db
# Full backup (database + files)
php artisan backup:run
The --only-db flag creates a smaller archive containing only the MySQL dump, while omitting it includes uploaded asset files and other storage.
Method 3: API Endpoint
Authenticated API clients can trigger backups remotely by posting to the backup endpoint defined in routes/api.php. This is useful for integrating Snipe-IT into broader infrastructure automation tools.
Scheduling Automatic Backups
To run nightly database backups without manual intervention, add the command to app/Console/Kernel.php:
protected function schedule(Schedule $schedule)
{
$schedule->command('backup:run --only-db')
->dailyAt('02:00')
->onFailure(function () {
// Optional: notify admin on failure
});
}
The Laravel scheduler requires a system cron entry to trigger every minute:
* * * * * cd /path/to/snipe-it && php artisan schedule:run >> /dev/null 2>&1
Customizing Backup Settings
Snipe-IT stores backups on the backup disk (default: storage/app/backups) outside the web root to prevent unauthorized access. Customize behavior by editing config/backup.php:
- Retention: Adjust
keep_all_backups_for_daysand related keys to control how long daily, weekly, and monthly backups are retained. - File Inclusion: Modify the
includeandexcludearrays to add directories like custom themes or exclude temporary files. - Storage: Change the
disksarray inconfig/backup.phpto use S3 or other remote storage defined inconfig/filesystems.php.
Restoring a Snipe-IT Database Backup
Restoration is a manual process performed outside the web interface:
- Download the desired backup from the UI or API to your local machine.
- Extract the zip archive and locate the
.sqldump file. - Import the database using MySQL:
mysql -u snipe_user -p snipe_database < /path/to/extracted/backup.sql
- Clear caches to prevent stale data:
php artisan optimize:clear
If restoring to a fresh instance or after schema changes, run migrations after importing:
php artisan migrate
Summary
- Snipe-IT uses spatie/laravel-backup for database and file backups, configured in
config/backup.php. - Create backups via the web UI (Settings → Backups), Artisan command
backup:run --only-db, or API endpoints. - Store backups automatically in
storage/app/backupsor configure remote disks like S3 inconfig/filesystems.php. - Schedule automated backups by adding the command to
app/Console/Kernel.phpand setting up a system cron. - Restore by extracting the zip and importing the SQL dump manually, then clearing caches with
php artisan optimize:clear.
Frequently Asked Questions
Where are Snipe-IT backup files stored?
By default, backups are stored in storage/app/backups on the local disk named backup. This location is outside the web document root to prevent direct URL access. You can configure additional storage disks like Amazon S3 in config/filesystems.php and reference them in config/backup.php.
How do I backup only the Snipe-IT database without files?
Append the --only-db flag to the Artisan command: php artisan backup:run --only-db. This creates a smaller zip archive containing only the MySQL dump using the mysqldump options defined in config/database.php, excluding uploaded asset images and other storage files.
Can I automate Snipe-IT database backups?
Yes. Add the backup command to app/Console/Kernel.php inside the schedule() method, specifying frequency (e.g., ->dailyAt('02:00')). Then configure a system cron to run php artisan schedule:run every minute. The postBackups() method in SettingsController.php demonstrates how the application handles backup generation logic that the scheduler triggers.
What permissions are required to create or download backups?
Only users with the admin role can generate or download backups. The SettingsController::postBackups() method explicitly checks Gate::allows('admin') before executing backup commands. API endpoints similarly enforce authentication and admin-level authorization.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →