Homepage Forums RetroPie Project Everything else related to the RetroPie Project How I backup my saved games (RPI2)

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #88644
    sselph
    Participant

    After getting a raspberry pi 2 and having a little more power, I decided to create a method to keep my saved games in a versioned backup. I got it figured out so thought I’d share it. I’ll go ahead and warn you that it is somewhat advanced but I’ll try and explain as best I can. The high level explanation is, I’ve turned RetroPie/roms into a git repository that is sync’d to a samba share and have a script that monitors for changes, commits them, then pushes that to the remote repository. I went this route because it seemed to have some cool possibilities in the future. In Go, the language my script is written in, it is trivial to start a web server. That combined with git’s ability to revert and branch I thought I could possibly have a server running where it could be easy to revert to previous states or switch users, etc.

    DISCLAIMER:
    I have tested this and it seems to work great but I haven’t tested all situations or run it for an extended period of time. As with any script that is going to making changes to your saves, you should probably manually backup before running it.

    This portion assumes you are doing this over a samba share. I already have a NAS with samba running so was easy but you could use ssh to a server or even github if you set it up so the git push doesn’t require user interaction using keys etc.

    First I created the samba share mount folder
    $ sudo mkdir /mnt/public

    Set the samba share to mount on boot by adding this line to /etc/fstab where 192.168.1.52 is my NAS’s ip and public is the name of the share.
    //192.168.1.52/public/ /mnt/public cifs guest,uid=1000,iocharset=utf8 0 0

    Mount the directory so we don’t have to reboot
    $ sudo mount /mnt/public

    Create the empty remote git repository

    $ cd /mnt/public
    $ git init --bare backup.git

    Now on to the raspi portion

    If you haven’t set up git add a user and email

    $ git config --global user.name "John Doe"
    $ git config --global user.email 

    Create the local git repository

    $ cd ~/RetroPie/roms/
    $ git init .
    $ git remote add origin file:///mnt/public/backup.git

    Create a .gitignore file containing the following. I only use retroarch with nes and snes so *.srm and *.state are the only 2 it uses. If there are other emulators that create different files you’ll have to add lines for those.

    # Ignore everything
    *
    
    # But these files...
    !.gitignore
    !*.srm
    !*.state
    
    !*/

    Then add all your current saves to repository

    $ git add -A
    $ git commit -a -m "Initial commit"
    $ git push origin master

    Now we have everything backed up to the remote repository and this point you could create a cron to cd to the roms dir then run the 3 commands. to keep it in sync. I took it one step further and create a service that monitors for changes then runs the commands to back everything up.

    To get the app and have it run every time at boot you’d do

    $ cd ~
    $ wget http://storage.googleapis.com/stevenselph.appspot.com/romsave.zip
    $ unzip romsave.zip
    $ sudo mv romsave.init /etc/init.d/romsave
    $ sudo chmod +x /etc/init.d/romsave
    $ sudo sudo update-rc.d romsave defaults
    $ sudo /etc/init.d/romsave start

    If you wanted more than just *.srm and *.state you’d have to open /etc/init.d/romsave before you run it to edit the line that starts the script to add the -extensions flag to add extensions. Also if you do anything manually to revert back to previous states be sure to stop the romsave service beforehand

    When you need to restore a backup on a new system you skip creating the remote repository and on the raspberry pi you do the following to get everything sync’d.

    $ cd ~/RetroPie/roms
    $ git init
    $ git remote add origin file:///mnt/public/backup.git
    $ git pull origin master
Viewing 1 post (of 1 total)
  • The forum ‘Everything else related to the RetroPie Project’ is closed to new topics and replies.