ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Rsync SSH

by davidolrik ST3

Keep remote directories in sync with local projects.

Labels sync

Details

Installs

  • Total 5K
  • Win 1K
  • OS X 2K
  • Linux 1K
Oct 21 Oct 20 Oct 19 Oct 18 Oct 17 Oct 16 Oct 15 Oct 14 Oct 13 Oct 12 Oct 11 Oct 10 Oct 9 Oct 8 Oct 7 Oct 6 Oct 5 Oct 4 Oct 3 Oct 2 Oct 1 Sep 30 Sep 29 Sep 28 Sep 27 Sep 26 Sep 25 Sep 24 Sep 23 Sep 22 Sep 21 Sep 20 Sep 19 Sep 18 Sep 17 Sep 16 Sep 15 Sep 14 Sep 13 Sep 12 Sep 11 Sep 10 Sep 9 Sep 8 Sep 7 Sep 6
Windows 0 0 2 1 0 0 0 0 0 0 0 1 2 1 0 1 2 0 0 2 0 0 0 2 0 2 2 1 1 0 0 0 0 1 0 0 2 3 2 1 1 1 0 0 1 1
OS X 0 0 3 0 1 2 2 1 1 1 1 1 4 3 1 0 0 3 1 2 5 0 0 2 1 1 1 2 0 1 2 2 1 2 3 1 1 4 1 2 6 2 1 1 1 0
Linux 0 0 2 0 0 0 0 0 3 0 0 0 0 0 2 2 2 1 2 3 1 0 0 0 0 0 1 1 0 0 1 1 1 1 0 0 1 2 1 0 0 2 2 0 2 3

Readme

Source
raw.​githubusercontent.​com

Sublime Rsync SSH

Keep remote directories in sync with local project folders.

Description

This plugin will let you sync your project folders to one or more remote servers using rsync and ssh.

Terminology

  • A remote is a local project folder configured for sync.
  • A destination is a path on specific server as a specific user.
  • A remote can have one or more destinations

Features

  • Edit locally, work remotely
  • Upload one or more project folders to one or more remote servers.
  • Each project folder can have multiple remotes, and each remote can have multiple destinations
  • Sync whole project or just a single remote or destination
  • Single file save only syncs the file being saved.
  • Auto generate initial rsync-ssh configuration for all folders in a project.
  • Exclude files, either for the whole project, a single fold or just a single remote.
  • Selective sync: Only sync part of a project folder to remote server.
  • Hooks for running a command on the remote host before and after sync.
  • Enable/Disable remotes.
  • Parse arguments to rsync for advanced usage (or features not yet included)
  • Detailed console output so you know what gets synced where.

Requirements

  • You must have both ssh and rsync installed, both locally and on the remote server.
  • You must have a ssh-key that allows you to perform login without password. If you have a password on your key, then you must use ssh-agent. On OS X you'll need to add your keys to the Keychain by using ssh-add -K, once this is done OS X will use ssh-agent to query the Keychain for your password.
  • On the remote server, you must add your ssh public key to ~/.ssh/authorized_keys.

For more info on creating and using ssh keys please see this nice guide.

Usage

Note you can see everything this plugin does by viewing its output on the console.

Initialize configuration

First create a Sublime Project, you do this by adding one or more folders and then saving your project.

Then you go to the Project menu and select Rsync SSH and then Initialize Settings, this will add the rsync_ssh block to settings with some reasonable defaults and then open the preferences for you to edit.

Be aware that the --delete option will destroy the directory you speficy in remote_path - as a courtesy I've added --dry-run so you can test your config before running rsync for real.

Example .sublime-project file

Note that the .sublime-project is a JSON file, and as such comments are not supported, fortunately for us Sublime Text uses a a rather lax parser that supports // comments. The comments below have just been added to document the individual sections .

When you initialize your project via Initialize Settings the plugin will add the rsync_ssh config to your project file.

{
    "folders":
    [
        {
            "follow_symlinks": true,
            "path": "my-project-folder"
        }
    ],
    "settings":
    {
        // This is the block the plugin adds to your project file
        "rsync_ssh":
        {
            // To use non-standard ssh specify the path here
            "ssh_binary": "/usr/local/bin/ssh",

            // To disable sync on save set 'sync_on_save' to false
            "sync_on_save": true,

            // Rsync options
            "options":
            [
                "--dry-run",
                "--delete",
                // Override how we handle permissions, useful for platforms that does not support Unix permissions.
                // Here we tell rsync to use the umask on the destination to set the permissions
                "--no-perms", "--chmod=ugo=rwX"
            ],
            // Stuff we do not want rsync to copy
            "excludes":
            [
                ".git*",
                "_build",
                "blib",
                "Build"
            ],
            // Servers we want to sync to
            "remotes":
            {
                // Each folder from the project will be added here
                "my-project-folder":
                [
                    {
                        // You can disable any destination by setting this value to 0
                        "enabled": 1,
                        // Stuff we do not want rsync to copy, but just for this destination
                        "excludes":
                        [
                        ],
                        // ssh options
                        "remote_host": "my-server.my-domain.tld",
                        "remote_path": "/home/you/Projects/my-project",
                        "remote_port": 22,
                        "remote_user": "you",
                        // Run commands before and after rsync
                        "remote_pre_command": "",
                        "remote_post_command": ""
                    }
                ],
                // Syncing a single subfolder is also supported
                "my-project-folder/subfolder":
                [
                    {
                        // You can disable any destination by setting this value to 0
                        "enabled": 0,
                        // Stuff we do not want rsync to copy, but just for this destination
                        "excludes":
                        [
                        ],
                        // ssh options
                        "remote_host": "my-server.my-domain.tld",
                        "remote_path": "/home/you/Projects/my-subfolder-target",
                        "remote_port": 22,
                        "remote_user": "you",
                        // Run commands before and after rsync
                        "remote_pre_command": "",
                        "remote_post_command": ""
                    }
                ]
            }
        }
    }
}

Sync single file

Just save the file normally, as this will trigger a save event which makes this plugin sync the file to all enabled remotes.

Sync specific remote or destination

Press ⌘⇧F11 to select a specific remote or destination to sync. When selecting a specific destination the enabled flag is overridden and the folder will always be synced. If you select a remote, and then select the All destination, then the enabled flag will be respected. If you select a remote with just one destination sync will started immediately and the enabled flag will be overridden.

Sync full project

Press ⌘⇧F12 to sync all folders to all enabled remotes. - Note you must do this at least once in order to create the project folder on the remote servers.

Installation

You install this plugin either by cloning this project directly, or by installing it via the excellent Package Control plugin. Press ⌘⇧P and type Package Control: Install Package and select it, then type the package name rsync-ssh and select it.

To use this plugin on Windows you must install Cygwin first.

F.A.Q.

When I try to sync, nothing happens

You probably forgot to remove --dry-run from the rsync options in the project configuration file.

I'm on Windows, how do I get sane permissions on the destination

As Windows doesn't have native support for Unix permissions, you can't rely on the default sync mode of “preserve permissions”. Instead you can turn off the persission sync with --no-perms and then use --chmod=ugo=rwX to make rsync use the umask on the destination to determine which permissions a file should have. When you initialize the rsync-ssh configuration this will be automatically added to the configuration as shown in the example above.

TODO

  • Rename remotes to folders (Calling them remotes is kinda silly).

License

© 2013-2015 David Olrik <david@olrik.dk>.

This is free software. It is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License. Feel free to use this package in your own work. However, if you modify and/or redistribute it, please attribute me in some way, and distribute your work under this or a similar license.