Files
mtc-project-sync-script/README.md

160 lines
4.2 KiB
Markdown
Raw Normal View History

2025-11-19 10:04:36 +02:00
# MTC Project Sync Script
2025-12-07 23:21:23 +02:00
A simple toolkit for synchronizing projects between remote servers and local development environments.
2025-10-22 10:50:38 +03:00
2025-12-07 23:21:23 +02:00
## Setup
2025-10-22 10:50:38 +03:00
2025-12-07 23:21:23 +02:00
### 1. Clone the Repository
2025-11-19 10:04:36 +02:00
```bash
cd ~/Documents/GitHub
git clone <repository-url> mtc-project-sync-script
```
2025-10-22 10:50:38 +03:00
2025-12-07 23:21:23 +02:00
### 2. Create a Symlink in Your Projects Directory
2025-10-22 10:50:38 +03:00
2025-12-07 23:21:23 +02:00
Navigate to where you keep all your projects and create a symbolic link to the sync script:
2025-11-19 10:04:36 +02:00
```bash
2025-12-07 23:21:23 +02:00
cd ~/Documents/Projects # or wherever you keep your projects
2025-11-19 10:04:36 +02:00
ln -s ~/Documents/GitHub/mtc-project-sync-script/sync-project.sh sync-project.sh
```
2025-12-07 23:21:23 +02:00
**Why symlink?** The script uses its own location to find the `scripts/` folder and `lazygit` binary. A symlink preserves the connection to the original script location, so it can access these resources. This way, you only need one copy of the toolkit that all your projects can use.
2025-10-22 10:50:38 +03:00
2025-12-07 23:21:23 +02:00
### 3. Run the Sync Script
2025-11-19 10:04:36 +02:00
2025-12-07 23:21:23 +02:00
From your projects directory, run:
2025-11-19 10:04:36 +02:00
```bash
./sync-project.sh
```
2025-12-07 23:21:23 +02:00
Or for SFTP-only setup (skips lazygit and .gitignore modifications):
2025-11-19 10:04:36 +02:00
2025-10-22 10:50:38 +03:00
```bash
2025-12-07 23:21:23 +02:00
./sync-project.sh --sftp-only
2025-11-19 10:04:36 +02:00
```
2025-12-07 23:21:23 +02:00
## What the Script Does
2025-11-19 10:04:36 +02:00
2025-12-07 23:21:23 +02:00
When you run `sync-project.sh`, it will:
2025-11-19 10:04:36 +02:00
2025-12-07 23:21:23 +02:00
1. **Ask for configuration:**
- Server user@host (e.g., `user@example.com`)
- Server project path (e.g., `/home/user/public_html`)
- Local folder path (e.g., `my-project`)
- SSH password
2025-11-19 10:04:36 +02:00
2025-12-07 23:21:23 +02:00
2. **Sync your project:**
- Creates a tar archive on the remote server
- Downloads and extracts it to your local folder
- Cleans up temporary files
2025-11-19 10:04:36 +02:00
2025-12-07 23:21:23 +02:00
3. **Generate configuration and scripts:**
- Creates `.vscode/sftp.json` for VS Code SFTP extension
- Generates helper scripts with your credentials pre-configured
- Adds scripts to `.gitignore` (unless using `--sftp-only`)
- Uploads lazygit to server (unless using `--sftp-only`)
2025-11-19 10:04:36 +02:00
2025-12-07 23:21:23 +02:00
## Generated Scripts
2025-11-19 10:04:36 +02:00
2025-12-07 23:21:23 +02:00
After running the sync script, you'll have these helper scripts in your project:
2025-11-19 10:04:36 +02:00
2025-12-07 23:21:23 +02:00
### `remote-local.sh`
**Purpose:** Download files from server to local machine
2025-11-19 10:04:36 +02:00
2025-12-07 23:21:23 +02:00
**What it does:**
- Uses rsync to pull files from remote server
- Only downloads changed files
- Excludes common development folders (node_modules, vendor, .git, etc.)
2025-11-19 10:04:36 +02:00
2025-12-07 23:21:23 +02:00
**Use cases:**
- Get latest changes from server
2025-11-19 10:04:36 +02:00
- Pull production data for debugging
2025-12-07 23:21:23 +02:00
- Sync before starting work
2025-11-19 10:04:36 +02:00
2025-12-07 23:21:23 +02:00
### `local-remote.sh`
**Purpose:** Upload files from local machine to server
2025-11-19 10:04:36 +02:00
2025-12-07 23:21:23 +02:00
**What it does:**
- Uses rsync to push files to remote server
- Only uploads changed files
- Deletes remote files that don't exist locally
- Excludes common development folders
2025-11-19 10:04:36 +02:00
2025-12-07 23:21:23 +02:00
**Use cases:**
- Deploy local changes to server
- Push code updates
- Restore server from local backup
2025-11-19 10:04:36 +02:00
2025-12-07 23:21:23 +02:00
### `ssh.sh`
**Purpose:** SSH into the remote server
2025-11-19 10:04:36 +02:00
2025-12-07 23:21:23 +02:00
**What it does:**
- Opens an SSH connection to your server
- Changes directory to your project path
- Supports `--db` flag for MySQL port forwarding
2025-11-19 10:04:36 +02:00
2025-12-07 23:21:23 +02:00
**Usage:**
2025-11-19 10:04:36 +02:00
```bash
2025-12-07 23:21:23 +02:00
./ssh.sh # Normal SSH connection
./ssh.sh --db # SSH with MySQL port forwarding (local:3306 -> remote:3306)
2025-11-19 10:04:36 +02:00
```
2025-12-07 23:21:23 +02:00
**Use cases:**
- Run commands on the server
- Check logs
- Access remote database via localhost:3306
2025-11-19 10:04:36 +02:00
2025-12-07 23:21:23 +02:00
### `sftp-watch.sh`
**Purpose:** Continuous bidirectional sync
2025-11-19 10:04:36 +02:00
2025-12-07 23:21:23 +02:00
**What it does:**
- First runs `remote-local.sh` to sync down
- Watches for local file changes
- Automatically runs `local-remote.sh` when files change
2025-11-19 10:04:36 +02:00
2025-12-07 23:21:23 +02:00
**Requirements:** Needs `watchexec` installed (`brew install watchexec`)
2025-11-19 10:04:36 +02:00
2025-12-07 23:21:23 +02:00
**Use cases:**
- Development with live server testing
- Real-time sync during coding
2025-11-19 10:04:36 +02:00
2025-12-07 23:21:23 +02:00
### `watch-build.sh`
**Purpose:** Watch for changes, build, and upload
2025-11-19 10:04:36 +02:00
2025-12-07 23:21:23 +02:00
**What it does:**
- Monitors files for changes
- Runs `npm run build` when changes detected
- Uploads built assets to server using `local-remote.sh`
2025-11-19 10:04:36 +02:00
2025-12-07 23:21:23 +02:00
**Requirements:**
- `watchexec` installed
- `package.json` with build script
- Node.js/npm installed
2025-10-22 10:50:38 +03:00
2025-12-07 23:21:23 +02:00
**Use cases:**
- Frontend development with build steps (React, Vue, etc.)
- Automatic deployment of compiled assets
- Continuous integration during development
2025-11-19 10:04:36 +02:00
2025-12-07 23:21:23 +02:00
## Requirements
2025-11-19 10:04:36 +02:00
2025-12-07 23:21:23 +02:00
- **bash** - Shell scripting
- **ssh/scp** - Remote server access
- **sshpass** - Password authentication
- **tar** - Archive creation
- **rsync** - File synchronization
- **watchexec** (optional) - For watch mode scripts
2025-11-19 10:04:36 +02:00
2025-12-07 23:21:23 +02:00
### Install on macOS:
2025-11-19 10:04:36 +02:00
```bash
2025-12-07 23:21:23 +02:00
brew install sshpass rsync watchexec
2025-11-19 10:04:36 +02:00
```
2025-12-07 23:21:23 +02:00
### Install on Ubuntu/Debian:
2025-11-19 10:04:36 +02:00
```bash
2025-12-07 23:21:23 +02:00
sudo apt-get install sshpass rsync openssh-client
2025-11-19 10:04:36 +02:00
```