定制 jorisnoo/laravel-remote-sync 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jorisnoo/laravel-remote-sync

Composer 安装命令:

composer require jorisnoo/laravel-remote-sync

包简介

Sync database and files from remote Laravel hosts using laravel-db-snapshots and rsync

README 文档

README

Latest Version on Packagist GitHub Tests Action Status Total Downloads

Pull a remote Laravel app's database and storage files to your local machine, or push them the other way. Database dumps use spatie/laravel-db-snapshots on the remote; file transfers use rsync over SSH.

Requirements

Locally:

  • PHP 8.3+, Laravel 11, 12, or 13
  • A mysql or pgsql database (imports pipe through the mysql/psql CLI)
  • ssh, rsync, and gzip on your PATH
  • SSH key access to the remote

On each remote:

  • spatie/laravel-db-snapshots and laravel/tinker installed
  • rsync
  • A PHP binary that satisfies the app. The default php is tried first, then versioned binaries (php8.5, php8.4, ...). You can also pin one with php_binary in the config.

The remote's snapshot location, database driver, and deployment layout are discovered automatically on every run - the remote's own configuration is what counts, so local and remote snapshot disks do not need to match.

Installation

composer require jorisnoo/laravel-remote-sync
php artisan vendor:publish --tag="remote-sync-config"

Configure a snapshots disk for spatie/laravel-db-snapshots in config/filesystems.php (on both sides, but they may differ):

'disks' => [
    'snapshots' => [
        'driver' => 'local',
        'root' => database_path('snapshots'),
    ],
],

Then point your .env at the remote:

REMOTE_SYNC_PRODUCTION_HOST=forge@your-server.com
REMOTE_SYNC_PRODUCTION_PATH=/home/forge/your-app.com

Verify the whole setup before the first sync:

php artisan remote-sync:doctor

Doctor checks your local binaries and, for each configured remote, the SSH host key, application path, PHP binary, installed packages, rsync, and driver compatibility.

Configuration

The published config/remote-sync.php:

return [
    'remotes' => [
        'production' => [
            'host' => env('REMOTE_SYNC_PRODUCTION_HOST'),
            'path' => env('REMOTE_SYNC_PRODUCTION_PATH'),
            'push' => (bool) env('REMOTE_SYNC_PRODUCTION_PUSH', false),
            // 'php_binary' => '/usr/bin/php8.4',
        ],
    ],

    // Used when several remotes are configured and none is passed.
    'default' => env('REMOTE_SYNC_DEFAULT'),

    // Storage-relative paths synced by the files scope.
    'paths' => ['app'],

    // Extra rsync excludes. Dotfiles and snapshot directories are always excluded.
    'exclude_paths' => [],

    // Synced as empty tables on pull, preserved on push. The migrations
    // table is always synced and `migrate --force` runs after every import.
    'exclude_tables' => ['cache', 'sessions', 'jobs', /* ... */],

    // false, or emails / *-wildcards of users to KEEP locally after a pull.
    'filter_users' => false,

    // Pull and push refuse to run when app.env is production unless this is true.
    'allow_production' => false,

    'timeouts' => [
        'remote' => 300,      // short remote commands
        'transfer' => 1800,   // dumps, imports, rsync transfers
    ],
];

Add more remotes by repeating the pattern - the env var names follow the remote's key (staging reads REMOTE_SYNC_STAGING_HOST, and so on). Remotes with missing or placeholder values are rejected with a message naming the exact env var to set.

Pulling

php artisan remote-sync:pull

Interactively this asks at most three things: which remote (only when several are configured), what to pull (database, files, or both), and one final confirmation - after showing you a plan of exactly what will happen: which tables are imported and truncated, which files are transferred, what a --delete pass would remove, and which backup is created.

Everything else is a flag:

Flag Effect
--database / --files Select the scope (skips the prompt; neither means both)
--full Import all tables, dropping local tables first
--no-backup Skip the local pre-pull-* backup snapshot
--keep-snapshot Keep the downloaded snapshot file after import
--delete Delete local files that no longer exist on the remote
--path=app/public Sync only specific storage-relative paths (repeatable)
--dry-run Print the plan and exit without changing anything
--force / -f Answer the final confirmation with yes

A standard pull creates a local backup, dumps the remote database (minus exclude_tables), downloads and integrity-checks the snapshot, imports it through the mysql/psql CLI, truncates the excluded tables, then runs migrate --force and optimize:clear. If the import fails, the downloaded snapshot is kept and the exact restore command for your backup is printed.

Deletion is strictly opt-in: --force never implies --delete, and the plan preview tells you how many local-only files a --delete pass would remove before you commit to anything.

For a cron or CI refresh:

php artisan remote-sync:pull production --database --files --force

Without --force, non-interactive runs print the plan and exit with an error, so a misconfigured cron line cannot sync anything by accident.

Pushing

Pushing overwrites data on the remote, so it is stricter:

php artisan remote-sync:push staging --database
  • The remote must have 'push' => true in its config.
  • Non-interactive runs must state the scope explicitly (--database and/or --files).
  • The interactive confirmation requires typing yes.

A database push backs up the remote first (pre-push-*), uploads a local snapshot, loads it on the remote without dropping tables (excluded tables are preserved), and runs remote migrations. If the load fails, the restore command for the remote backup is printed. Flags mirror pull: --no-backup, --delete, --path=, --dry-run, --force.

Pruning snapshots

Transfer snapshots are removed automatically after each run, but backups (pre-pull-*, pre-push-*) accumulate:

php artisan remote-sync:prune                      # local + remote, keep the 5 newest
php artisan remote-sync:prune --local --keep=3
php artisan remote-sync:prune production --remote --dry-run

Prune only touches snapshots created by this package (remote-sync-*, pre-pull-*, pre-push-*). Pass --all to include your own spatie snapshots as well.

Safety

  • Pull and push refuse to run when the local app environment is production; set allow_production to true only when that is intentional (the confirmation then requires a typed yes).
  • One plan preview and one confirmation before anything changes; --dry-run everywhere.
  • Backups are created by default on both directions, and every failure message includes the command to restore.
  • Unknown SSH hosts show their key fingerprint for review before connecting; changed host keys abort with a man-in-the-middle warning, and non-interactive runs never accept a new host key.
  • Interrupting a run (Ctrl+C) removes temporary snapshots on both sides.
  • filter_users refuses to act when its patterns would delete every user.

Security notes

  • Database passwords are handed to mysql/psql via the MYSQL_PWD/PGPASSWORD environment variables, never as command-line arguments.
  • Sync paths are validated against a strict character allowlist before being used in remote rsync specs.
  • Use SSH keys; the package never handles SSH passwords.

Testing

composer test

License

The MIT License (MIT). Please see License File for more information.

Built with Claude Code.

jorisnoo/laravel-remote-sync 适用场景与选型建议

jorisnoo/laravel-remote-sync 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 755 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 jorisnoo/laravel-remote-sync 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 jorisnoo/laravel-remote-sync 我们能提供哪些服务?
定制开发 / 二次开发

基于 jorisnoo/laravel-remote-sync 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 755
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 38
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-20