Let's improve my "trick" from the last post a little bit, by adding staging and qa.
Below a visualisation, in remote
are the symlinks to the mountpoints of the remote directory (e.g. via GVS or SSHFS), in mirror
the directories you rsync
with first to get the batch file and in batch
you store the batch files genearted by rsync
.
- remote
- prod (symlink)
- qa (symlink)
- stg (symlink)
- mirror
- prod (dir)
- qa (dir)
- stg (dir)
- batch
- prod (dir)
- qa (dir)
- stg (dir)
vfs-rsync-upload
Creating the directory structure and the symlinks for each project and run the rather long rsync
command by hand is al little bit unhandy, so I wrote a little script for that, find it on gitlab.com/criztovyl/vfs-rsync-upload.
Setup a project
To set up the remotes for project (any directory) run the command below.
/path/to/mount
is the mount point of the remote directory, dist
the directory you want to upload and myproject
is the configuration name.
$ vfs-rsync-upload setup /path/to/mount dist myproject "--exclude /piwik --exclude /blog"
This creates some files and directories:
- a
.p12g
file in the current directory, containing a configuration key, which is appended to your configuration name to prevent name collisions. - a
.p12g
directory in your home ("p12g" for "publishing") and - a
myproject-configKey
directory in the.p12g
dir, with the structure outlined below:- remotes
- production (symlink to /path/to/mount)
- qa (symlink to /path/to/mount/qa)
- staging (symlink to /path/to/mount/staging)
- mirror
- production (dir)
- qa (dir)
- staging (dir)
- batch
- production (dir)
- qa (dir)
- staging (dir)
- sync_dir (symlink to dist)
- remotes
Afterwards it synchronizes the folders in remote
with the folders in mirrors
, using rsync
, appending the contents of the fifth argument to the defaults arguments (i.e.--write-batch=batch
), but note that this will not synchronize the contents of the current directory. Maybe I'll add that later.
Upload files
$ vfs-rsync-upload staging
This uploads the contents of dist
, as you set up above. As first this will rsync
the local mirror (mirrors/staging
) and the directory (dist
) and write a batch (batch/staging/batch
and batch/staging/batch.sh
). Afterwards it calls the batch.sh
and uploads the changes to your remote directory. Currently only staging
, qa
and production
are supported. In future you should be able to define your own "targets" too.