Jump to content

[BASH]Savefiles autosaver


Cakeofruit

Recommended Posts

Hello mac kerbaunauts !

This is a bash script that i'm working on.(still a WIP don't use if you don't know bash)

This is made to autosave your save files in kerbal and allow you to grab a old persistent.sfs that isn't corrupt by a craft randomly explode ( true story :huh:)

Make a new .command of .sh and make it excutable than that the code and paste it.

Then put this file in the save you want to save

This should works on linux but i'm not sure.

#!/bin/bash

#INIT

#*******************************************************************************************************************************************

clear

Adress=$0

dir=${Adress%/*}

dirdir=${dir%/*}

dirdirdir=${dirdir%/*}

Adresslength=${#Adress}

#source auto and folder name

Nametosave="Back_Up"

cd ${dirdirdir// /?}

mkdir $Nametosave

Source_auto=${dir// /\?}

Dest_auto=${dirdirdir// /?}/$Nametosave

#VARIABLES & CONFIGURATION

#*******************************************************************************************************************************************

cible=$Source_auto

ciblelog=$Dest_auto

Dest=$Dest_auto

interval=5

#nbbackup=20 Not use for now

#BigBackup=10 Not use for now

#END OF VARIABLES & CONFIGURATION, DON'T CHANGE AFTER THIS WARNING

#*******************************************************************************************************************************************

#Files log

cd $ciblelog

touch rsync.log

backup_log=$ciblelog/rsync.log

## need to create a intermadiate folder that contain the small update

while true ;do rsync -ravb --backup-dir=`date +%H:%M` $cible $Dest >> $backup_log;sleep $interval;done &

sleep 3600

kill $!; trap 'kill $!' SIGTERM

I'm open to any improvement you could thinks of.

To do list:

change the dest that it doesn't mess up the ksp files ( by creating invalid saves)

Make a others script to make a profile ( change the souce, Dest, and the interval) maybe in applescript or bash if my script works on ubuntu :wink:

secondary : built a xcode interface

Link to comment
Share on other sites

Neat. Instead of sleeping for an hour, you might want to launch KSP and wait till it closes, then kill the rsync. "open -W KSP.app" will launch KSP and wait for it to finish. If you use Steam, the Steam app runs and then exits, so you have you just check if KSP is running via "ps".

I'm also pretty sure the "trap" needs to be set up before you start waiting.

So, putting this together (and adding support for Linux KSP):


while true ;do rsync -ravb --backup-dir=`date +%H:%M` $cible $Dest >> $backup_log;sleep $interval;done &

RSYNCPID=$!
trap 'kill $RSYNCPID' SIGTERM

if [ -d "/Applications/KSP.app" ]; then
# Run the Steam launcher for KSP
open "/Applications/KSP steam.app"
# Wait for the real KSP app to start
sleep 60
# Wait for KSP to quit
while ( ps xa |grep [K]SP.app ); do
sleep 60;
done
elif [ -d /Applications/Kerbal Space Program/KSP.app ]; then
# Run the non-Steam version of KSP
open -W /Applications/Kerbal Space Program/KSP.app
elif which -s KSP.x86_64; then
KSP.x86_64
elif which -s KSP.x86; then
KSP.x86
else
echo "Can't find KSP!"
exit 1
fi

kill $RSYNCPID

I'll also point out that there's also other ways to accomplish the same thing:

1. I put my entire "saves" directory in Google Drive and make a symlink from my KSP directory. It auto-saves revisions, and backs up at the same time. Dropbox does the same thing. Mac and Linux can make a symlink with "ln -s"; on Windows it's "mklink /d". Then whenever the game auto-saves, a new revision is made. Same thing when you save a new quicksave (although now we have alt+f5 and alt+f9 for named quicksaves).

2. Windows has "previous versions" and OS X has Time Machine, though Time Machine doesn't run that often and might miss things.

Link to comment
Share on other sites

I know that dropbox and a simlink is a good alternative but i wanted a script that i can tweak and that i' m mastering.

I want to use this on my work and project so dropbox is out of the league :)

Time machine lost 3 h of careful flights to set up my RT networks.

nice piece of code to check if a app is launch i will try it ( see if it fit well in the script) .

i'm also trying to make a xcode interface but i really struggle ;(

ps : thx NathanKell to move this thread in the good location and for your awesome mods ;)

Link to comment
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.

×
×
  • Create New...