Sign in to follow this  
jonasrosland

Use Git to manage Kerbal Space Program saves, ships and CKAN mods

Recommended Posts

Great idea, regardless of whether you use CKAN or not. An easier way to do it might be to use a .gitignore file in the KSP root. However anyone does it, they should be certain they're not uploading Squad's IP to a public Github repo.

Share this post


Link to post
Share on other sites

But, don't you have to commit and push your save every time you leave the game?

Seems like Dropbox and symbolic links would be more automatic. (Does Mac have symbolic links?)

EDIT: Apparently it does. So yeah, put the save and GameData directory in Dropbox and then symbolic link it over to the KSP folder and the Dropbox app will upload changes automatically.

Edited by Alshain

Share this post


Link to post
Share on other sites
Great idea, regardless of whether you use CKAN or not. An easier way to do it might be to use a .gitignore file in the KSP root. However anyone does it, they should be certain they're not uploading Squad's IP to a public Github repo.

Yup, that's true. I added the scenario and tutorial folder to .gitignore, a better way could probably be to gitignore everything and just force the folders you want to sync.

- - - Updated - - -

But, don't you have to commit and push your save every time you leave the game?

Seems like Dropbox and symbolic links would be more automatic. (Does Mac have symbolic links?)

EDIT: Apparently it does. So yeah, put the save and GameData directory in Dropbox and then symbolic link it over to the KSP folder and the Dropbox app will upload changes automatically.

That's way too easy, that's not the Kerbal way!

- - - Updated - - -

Wouldn't a flash drive be easier?

You can do that too, but I wanted a way to share my stuff as well (like entire setups, saves, ships etc) for anyone who'd like to see anything someone else has created.

Share this post


Link to post
Share on other sites

If you want to use git, you could simply automate this - a rudimentary bash script could take care of all the the adding and committing. Personally, I just backup persistent.sfs after I quit, placed into dropbox with the time and date. Simple script, run it when I'm done, no thinking. Here's the source, also copied below:

#!/usr/bin/env bash
# ksp_backup_files.sh by Amory Meltzer
# Simply copy pilot files to a save directory

dateandtime=$(date +%Y.%m.%d_%H%M%S)
folderpath='/Users/Amory/Dropbox/KSPstuff/pilot_backups/'$dateandtime
ksppath='/Applications/KSP_osx'

userlist=$(ls -1 $ksppath'/saves' | grep -v scenarios | grep -v training)

mkdir "$folderpath"

for i in $userlist
do
cp "$ksppath/saves/$i/persistent.sfs" "$folderpath/$i.persistent.sfs"
done

ls -lFGh "$folderpath/"

Share this post


Link to post
Share on other sites

could work if you run KSP from a batch/command file and add the commands to update and commit the persistence file before and after running KSP. Trick is getting the script to wait until operations complete.

So:

- update

- wait for completion

- run KSP

- wait until KSP terminates (tricky as it's run in a different process?)

- commit

Share this post


Link to post
Share on other sites
But, don't you have to commit and push your save every time you leave the game?

Seems like Dropbox and symbolic links would be more automatic. (Does Mac have symbolic links?)

EDIT: Apparently it does. So yeah, put the save and GameData directory in Dropbox and then symbolic link it over to the KSP folder and the Dropbox app will upload changes automatically.

When you have over 300mb of gamedata files... wait long long for dropbox to sync!

Share this post


Link to post
Share on other sites
When you have over 300mb of gamedata files... wait long long for dropbox to sync!

Do your 300mb of mods change that frequently? If they do I would say you are doing something wrong. Dropbox only syncs files that change.

Share this post


Link to post
Share on other sites

I've used git to maintain my KSP saves for a long time, mostly to have version control, but it has also been useful to be able to push/pull saves about.

I don't init the repo in the root of KSP, I create a separate repo inside each save. So each repo just has craft and save files and no bits of Squad IP.

Initially I used to just manually add/commit files as I played, then I wrote a tool to automate it and make it so someone with zero git experience can use it: Jebretary, is a bit out of date, and has querks, but it still works in the current version of KSP (it's stand-alone so kinda immune to KSP update issues). Basically you tell it where KSP is installed (it can track multiple installs) and it sets up git repos in your save folders, then as you play KSP it watches for changes in files and automatically adds and commits them. It tracks every single change to persistent/quicksave files, with craft it waits until you launch the craft before committing, so you have a restore point for each variation that you launch (you can also tell it to commit whenever).

For tracking saves and craft files git is a perfect tool, it's something like 1000 times more space efficient while retaining the same resolution on changes. But I'm not so sure about using it on GameData; when dealing with binary files it can't track individual line changes, so the whole file is duplicated each time it's updated and committed, even if the only change was the file's timestamp. So if you have a mod with a large texture, each time that mod is updated it will get updated in the repo resulting in another copy of that large texture file. So repo size can balloon quite quickly when dealing with large binary files. And anyway, if you have a 2GB GameData folder and you commit it, you now also have a 2GB repo.

With CKAN (and assuming all your mods are available via CKAN), then you could use git to track your saves and also track the installed-default.ckan file in the CKAN folder along with each commit. That way you could restore the mods you had installed for a particular save-backup by giving that file to CKAN. So no need to add mods to repos (which might inadvertently get put somewhere public).

Share this post


Link to post
Share on other sites

For tracking saves and craft files git is a perfect tool, it's something like 1000 times more space efficient while retaining the same resolution on changes. But I'm not so sure about using it on GameData; when dealing with binary files it can't track individual line changes, so the whole file is duplicated each time it's updated and committed, even if the only change was the file's timestamp. So if you have a mod with a large texture, each time that mod is updated it will get updated in the repo resulting in another copy of that large texture file. So repo size can balloon quite quickly when dealing with large binary files. And anyway, if you have a 2GB GameData folder and you commit it, you now also have a 2GB repo.

Git Annex is the tool you are looking for.

https://git-annex.branchable.com/

You can keep files in git without actually keeping them in git :) This solves the problem with binary files in repo.

Share this post


Link to post
Share on other sites
could work if you run KSP from a batch/command file and add the commands to update and commit the persistence file before and after running KSP. Trick is getting the script to wait until operations complete.

So:

- update

- wait for completion

- run KSP

- wait until KSP terminates (tricky as it's run in a different process?)

- commit

You could grab the PID of the exec'd process (updater, KSP, backup) and wait and loop and watch for it to terminate (but I find that 'wasteful', plus you'd lose any termination/error conditions on exit) ... or ... you could trap the exec (a series of them, functions) and watch for desired exit signals, effectively 'pausing' the batch file, as well as monitoring/insuring the success of the backup itself.

Share this post


Link to post
Share on other sites

Something like inotifywait (lin) (win) can monitor a file/folder for changes and execute a command in result of that, dunno how often the savefile is changed during a KSP session, but I presume it's a lot which may lead to a lot of commits, and a very detailed carreer history also :)

Share this post


Link to post
Share on other sites

inotifywait would be ok to monitor the update/backup process itself (the files/folders involved), but better yet would be to trap the execution of git-annex as _stilgar_ suggests and mentions above. You'll want to act only on normal (successful) termination of each of the processes, because by then all open files would be closed.

Share this post


Link to post
Share on other sites

You should only put things in git that are relevant to your setup. Having Gamedata and all the mods there doesn't make sense IMHO. CKAN is special, since having the installed-default.ckan in git doesn't work, as it'll be overwritten first time you do a "ckan scan" or "ckan list". That's why I do a copy of the original to another file so I can keep that file up to date and use it to keep my CKAN install up to date.

I looked into Jebretary, it looks neat! I saw you needed some help with it as well, any specifics?

Share this post


Link to post
Share on other sites
This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this