Skip to content

Commit 071d20f

Browse files
committed
Initial project setup for Laravel Server Sync package
- Created configuration file for server sync settings - Implemented ServerSyncServiceProvider and SyncPullCommand - Added comprehensive README with usage instructions and features - Set up basic project structure for database and file synchronization
0 parents  commit 071d20f

File tree

7 files changed

+637
-0
lines changed

7 files changed

+637
-0
lines changed

.gitignore

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/vendor/
2+
/node_modules/
3+
composer.lock
4+
package-lock.json
5+
yarn.lock
6+
.phpunit.result.cache
7+
.phpunit.cache/
8+
coverage/
9+
.php-cs-fixer.cache
10+
.php_cs.cache
11+
12+
# IDE & Editors
13+
.idea/
14+
.vscode/
15+
*.sublime-project
16+
*.sublime-workspace
17+
*.code-workspace
18+
19+
# OS generated files
20+
.DS_Store
21+
.DS_Store?
22+
._*
23+
.Spotlight-V100
24+
.Trashes
25+
ehthumbs.db
26+
Thumbs.db
27+
28+
# Laravel specific
29+
storage/*.key
30+
.env
31+
.env.backup
32+
.env.*.local
33+
Homestead.json
34+
Homestead.yaml
35+
36+
# Testing
37+
phpunit.xml
38+
.phpunit.result.cache
39+
.coverage/
40+
coverage.xml
41+
*.lcov
42+
43+
# Logs
44+
*.log
45+
npm-debug.log*
46+
yarn-debug.log*
47+
yarn-error.log*
48+
49+
# Build directories
50+
/build/
51+
/dist/
52+
/public/storage
53+
/public/hot
54+
55+
# Local development
56+
/.vagrant
57+
.php_cs
58+
.php_cs.dist
59+
.phpstorm.meta.php
60+
_ide_helper.php
61+
_ide_helper_models.php
62+
.phpstorm.meta.php

LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) Figlab <[email protected]>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

+153
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# Laravel Server Sync
2+
3+
[![Latest Version on Packagist](https://img.shields.io/packagist/v/ajaxray/laravel-server-sync.svg?style=flat-square)](https://packagist.org/packages/ajaxray/laravel-server-sync)
4+
[![Total Downloads](https://img.shields.io/packagist/dt/ajaxray/laravel-server-sync.svg?style=flat-square)](https://packagist.org/packages/ajaxray/laravel-server-sync)
5+
[![License](https://img.shields.io/packagist/l/ajaxray/laravel-server-sync.svg?style=flat-square)](https://packagist.org/packages/ajaxray/laravel-server-sync)
6+
7+
A Laravel package to easily sync your production database and files to your local environment. Perfect for debugging production issues or keeping your local environment up to date with production data.
8+
9+
## Features
10+
11+
- 🔄 One-command sync of both database and files
12+
- 🔒 Secure SSH-based file transfer
13+
- 📁 Smart file syncing with rsync
14+
- 🗄️ Database dump and restore
15+
- ⚡ Progress indicators for long operations
16+
- 🛠️ Highly configurable
17+
18+
## Requirements
19+
20+
- PHP 8.1 or higher
21+
- Laravel 10.0 or higher
22+
- SSH access to production server
23+
- MySQL/MariaDB client installed locally
24+
- rsync installed on both local and production servers
25+
26+
## Installation
27+
28+
```bash
29+
composer require ajaxray/laravel-server-sync
30+
```
31+
32+
After installation, publish the configuration file:
33+
34+
```bash
35+
php artisan vendor:publish --provider="Ajaxray\ServerSync\ServerSyncServiceProvider"
36+
```
37+
38+
## Configuration
39+
40+
### Environment Variables
41+
42+
Add these to your `.env` file:
43+
44+
```env
45+
PROD_SSH_HOST=your-production-server.com
46+
PROD_SSH_USER=your-ssh-username
47+
PROD_SSH_PATH=/path/to/laravel
48+
```
49+
50+
### Configuration File
51+
52+
The published config file `config/server-sync.php` allows you to:
53+
54+
- Configure default server settings
55+
- Exclude specific tables from database sync
56+
- Configure file sync paths and exclusions
57+
- Customize dump location
58+
59+
## Usage
60+
61+
### Basic Usage
62+
63+
Sync both database and files:
64+
65+
```bash
66+
php artisan sync:pull
67+
```
68+
69+
### Database Sync Options
70+
71+
```bash
72+
# Skip database sync entirely
73+
php artisan sync:pull --skip-db
74+
75+
# Exclude specific tables
76+
php artisan sync:pull --exclude-tables=logs,cache,sessions
77+
78+
# Only sync specific tables
79+
php artisan sync:pull --only-tables=users,products,orders
80+
```
81+
82+
### File Sync Options
83+
84+
```bash
85+
# Skip file sync entirely
86+
php artisan sync:pull --skip-files
87+
88+
# Sync files with deletion (removes local files that don't exist in production)
89+
php artisan sync:pull --delete
90+
```
91+
92+
### Server Configuration Options
93+
94+
```bash
95+
# Override server details inline
96+
php artisan sync:pull --host=prod.example.com --user=deploy --path=/var/www/app
97+
98+
# All options can be combined
99+
php artisan sync:pull --host=prod.example.com --user=deploy --exclude-tables=logs --delete
100+
```
101+
102+
### Safety Features
103+
104+
```bash
105+
# Force sync in production environment (use with caution!)
106+
php artisan sync:pull --force
107+
```
108+
109+
> **Note**: The `--force` option should be used with extreme caution as it overrides the production environment safety check.
110+
111+
## Security
112+
113+
- Uses SSH for secure file transfer
114+
- Requires key-based authentication
115+
- Temporary files are automatically cleaned up
116+
- Database credentials are never stored locally
117+
118+
## Troubleshooting
119+
120+
### SSH Connection Issues
121+
122+
- Verify SSH key-based authentication is set up
123+
- Check if you can manually SSH into the server
124+
- Ensure proper permissions for the SSH user
125+
126+
### Database Sync Issues
127+
128+
- Verify MySQL client installation
129+
- Check database credentials in both environments
130+
- Ensure sufficient privileges for database operations
131+
132+
### File Sync Issues
133+
134+
- Verify rsync installation
135+
- Check storage directory permissions
136+
- Use stable internet connection for large files
137+
138+
## Contributing
139+
140+
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
141+
142+
## Security Vulnerabilities
143+
144+
Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
145+
146+
## Credits
147+
148+
- [Anis Uddin Ahmad](https://github.com/ajaxray)
149+
- [All Contributors](../../contributors)
150+
151+
## License
152+
153+
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

composer.json

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"name": "ajaxray/laravel-server-sync",
3+
"description": "A Laravel package to easily sync your production database and files to your local environment",
4+
"keywords": [
5+
"laravel",
6+
"sync",
7+
"database",
8+
"files",
9+
"production",
10+
"deployment"
11+
],
12+
"type": "library",
13+
"license": "MIT",
14+
"authors": [
15+
{
16+
"name": "Anis Uddin Ahmad",
17+
"email": "[email protected]"
18+
}
19+
],
20+
"require": {
21+
"php": "^8.1",
22+
"illuminate/support": "^10.0|^11.0",
23+
"illuminate/console": "^10.0|^11.0",
24+
"spatie/laravel-package-tools": "^1.16"
25+
},
26+
"require-dev": {
27+
"orchestra/testbench": "^8.0|^9.0",
28+
"phpunit/phpunit": "^10.5"
29+
},
30+
"autoload": {
31+
"psr-4": {
32+
"Ajaxray\\ServerSync\\": "src/"
33+
}
34+
},
35+
"autoload-dev": {
36+
"psr-4": {
37+
"Ajaxray\\ServerSync\\Tests\\": "tests/"
38+
}
39+
},
40+
"extra": {
41+
"laravel": {
42+
"providers": [
43+
"Ajaxray\\ServerSync\\ServerSyncServiceProvider"
44+
]
45+
}
46+
},
47+
"config": {
48+
"sort-packages": true
49+
},
50+
"minimum-stability": "dev",
51+
"prefer-stable": true
52+
}

config/server-sync.php

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
return [
4+
/*
5+
|--------------------------------------------------------------------------
6+
| Production Server Configuration
7+
|--------------------------------------------------------------------------
8+
|
9+
| These values will be used when no command line options are provided.
10+
| Configure your production server details here or in your .env file.
11+
|
12+
*/
13+
'production' => [
14+
'host' => env('PROD_SSH_HOST', ''),
15+
'user' => env('PROD_SSH_USER', ''),
16+
'path' => env('PROD_SSH_PATH', ''),
17+
],
18+
19+
/*
20+
|--------------------------------------------------------------------------
21+
| Database Sync Settings
22+
|--------------------------------------------------------------------------
23+
|
24+
| Configure database sync settings including dump location and tables to exclude.
25+
|
26+
*/
27+
'database' => [
28+
'dump_path' => storage_path('dumps'),
29+
'tables' => [
30+
'exclude' => [
31+
// Tables to exclude from sync, e.g.:
32+
// 'migrations',
33+
// 'password_reset_tokens',
34+
],
35+
],
36+
],
37+
38+
/*
39+
|--------------------------------------------------------------------------
40+
| File Sync Settings
41+
|--------------------------------------------------------------------------
42+
|
43+
| Configure which paths to sync from production and patterns to exclude.
44+
| The 'paths' array should contain absolute paths to directories you want to sync.
45+
| The 'exclude' array contains patterns for files/directories to exclude from sync.
46+
|
47+
*/
48+
'files' => [
49+
'paths' => [
50+
storage_path('app'),
51+
// Add more paths to sync, e.g.:
52+
// public_path('uploads'),
53+
],
54+
'exclude' => [
55+
'*.log',
56+
'.git',
57+
'node_modules',
58+
'vendor',
59+
'.env',
60+
'.env.*',
61+
],
62+
],
63+
];

0 commit comments

Comments
 (0)