Login





Create an Account

TacilePuppet


SSH/SCP Automated Syncronization

C#

Wrote this dude when I was redesigning this website. I wanted a utility that would quickly and easily replicate changes made to my local solution to the server. I think the program may kick a little ass right now, but I don't think I'm quite ready to release it just yet.

The program is composed of three modes controlled by two different json configuration files. The modes are as follows:

What I really like about this system is the awesomeness that is contained within the json files. Take this puppet_mirror.json file for example:

{
    "host_name" : "destinaction.com",
    "user_name" : "my_username",
    "home_directory" : "/home/",
    "private_key_filename" : "C:/my_private_key",
    "preserve_filenames" : [
        "logs",
        "tmp",
        "access-logs",
        "mail"
    ],
    "elements" : [
        {"filename" : "includes"},
        {"filename" : "tests"},
        
        {"filename" : "Application.php"},
        {"filename" : "execute_job.php"},
        
        {"filename" : "credentials-production.php", "target_filename" : "credentials.php"}
    ],
    "initilization_commands" : [
        "php execute_job.php Every5Minutes"
    ]
}

When running the program in Mirror mode, the program first asks for the passphrase to decrypt your private key, and then the awesome begins:

  1. Enumerates all the files in your destination home directory.
  2. Any enumerated file not contained within the list of "preserved_filenames" is recursively deleted on the destination server.
  3. A local archive is made composed of all the files listed in "elements". Additionally, each element within this list may specify a specific regular expression pattern to only upload filenames conforming to specific rules. Furthermore, and this is the really good bit, you can specify a "target_filename" for files or directories so that the directory structure is modified in transfer to the destination server.
  4. The local archive is transferred via SCP to the destination server.
  5. The now transferred archive is then decompressed and the archive is deleted.
  6. Each entry in "initilization_commands" is passed directly to the SSH stream, allowing for additional commands to be ran after upload to tidy up things.

When running the program in MirrorChanges mode, the program basically runs just like in Mirror mode, except no deletion takes place and only changes that occur while the program is running will be uploaded; however, all transformations defined within puppet_mirror.json will occur as though the files had been uploaded via Mirror mode.

The Backup mode I added to automate the process of backing up the project in an automated fashion that would be careful to not include credentials and/or other sensitive information.