Please do not post a support request without first reading and following the advice in https://retropie.org.uk/forum/topic/3/read-this-first

Backup SD Card by copying out files?



  • Has anyone tried to backup all of their files by simply copying all of the folders off of the SD card onto their hard drive and then installing a fresh image of retropie and copying all of the files back onto the new installation?

    The reason I ask is that over the last 2 months i have had 2 SD cards that have corrupted while creating a backup image on my computer. I have a good image which is my "Base Image" that i start all my build from, but then i put a lot of time into setting up controllers and other setting unique to each build, i like to then make a final backup incase the card every corrupts durring use. It sucks when the build is complete and you loose it during the backup process. If i could just have the files as folders and then create a new image and dump in the folders that would allow me to skip creating a final image of the card.


  • administrators

    @TMNTturtlguy as long as you have direct access to the file system.

    Though I'm only thinking of files I think you'd still have to make the sd bootable perhaps so I am not sure. I have tried to be honest



  • @herb_fargus i might give it a go...i am thinking that i install the my base image and make it bootable. Once it is up and running, i go into the file structure and replace files that have been modified, like the retroarch, emulationstation, and other config folders and files for the roms and controller settings.


  • Global Moderator

    @TMNTturtlguy

    Has anyone tried to backup all of their files by simply copying all of the folders off of the SD card onto their hard drive and then installing a fresh image of retropie and copying all of the files back onto the new installation?

    I've done this several times now without any issue. I wrote a script that runs every night and makes a backup of the necessary files to a thumbdrive and only keeps the two most recent backups. I prefer to do it this way for space reasons, as well as knowing that I can more easily move up to a new Raspbian whenever the time comes.



  • @mediamogul Sweet! I thought it might work. Do you by chance have a list of files/folders that you backup that you could send my way?


  • Global Moderator

    @TMNTturtlguy

    Sure. For me, those files and folders include:

    /boot/config.txt
    /etc/fstab
    /etc/udev/rules.d
    /etc/rc.local
    /etc/samba/smb.conf
    /opt/retropie/configs
    /home/pi/.config
    /home/pi/.local
    /home/pi/.openMSX
    /home/pi/.q3a

    Edit: My /home/pi/Retropie folder is already external, so it's not included.



  • @mediamogul said in Backup SD Card by copying out files?:

    @TMNTturtlguy

    Has anyone tried to backup all of their files by simply copying all of the folders off of the SD card onto their hard drive and then installing a fresh image of retropie and copying all of the files back onto the new installation?

    I've done this several times now without any issue. I wrote a script that runs every night and makes a backup of the necessary files to a thumbdrive and only keeps the two most recent backups. I prefer to do it this way for space reasons, as well as knowing that I can more easily move up to a new Raspbian whenever the time comes.

    Could you post your script, this would help a lot of people who don't want to lose all the effort they put it to get RetroPie running how they want it to in case of SD Card corruption or otherwise and add backup support

    Thanks


  • Global Moderator

    @steptoe said in Backup SD Card by copying out files?:

    Could you post your script

    Can do:

    #!/bin/sh
    ##Change the numeral in "head -n -*" to however many backups are to be kept.
    
    foldername=$(date +%Y%m%d%H%M%S) && \
    mkdir -p /media/usb0/Backups/RetroPie/"$foldername" && \
    sudo cp -rfv \
    	/boot/config.txt \
    	/etc/fstab \
    	/etc/udev/rules.d \
    	/etc/rc.local \
    	/etc/samba/smb.conf \
    	/opt/retropie/configs \
    	/home/pi/.config \
    	/home/pi/.local \
    	/home/pi/.openMSX \
    	/home/pi/.q3a \
    	/media/usb0/Backups/RetroPie/"$foldername"/
    cd /media/usb0/Backups/RetroPie/ && \
    ls -1tr | head -n -2 | xargs -d '\n' rm -rfv --
    clear
    
    


  • @mediamogul this is great! Is this script just a one time copy that I can run every time I want to make a copy? Also, is is possible to change the location form the USB to a location over the network? Or do I need to make the copy to a USB? Thanks for this! It will be very useful!


  • Global Moderator

    @TMNTturtlguy

    is this script just a one time copy that I can run every time I want to make a copy?

    I run it in two different ways. First, the actual script resides in /home/pi/RetroPie/retropiemenu. That way, I can navigate to the RetroPie menu in Emulation Station and launch it manually whenever I want. Secondly, I have it set as a scheduled Cron task that launches every morning at 4:00am automatically.

    Also, is is possible to change the location form the USB to a location over the network?

    Sure. If you have any network shares mounted at boot, you can just point the script in their direction.



  • @mediamogul probably a dumb question but I am on my phone so I can't test the script right now, but in the last line above clear in you script post the 'n' shows up in green like the "filename" which is Kent to be user modified. Is the 'n' supposed to be modified or is that green just because the forum post sees the ' on either side.

    Thanks, this is really cool!


  • Global Moderator

    @TMNTturtlguy

    or is that green just because the forum post sees the ' on either side.

    It's just the forum post.



  • I personally backup the entire /opt/retropie/ folder. So if i get an emulator that no longer works, i can put the old one on. Example: the new lr-mame2010 no longer works at all. So i have to put the old one on.


  • Global Moderator

    @edmaul69

    Very wise. I've thought about doing the same.



  • @mediamogul i actually backup files as i add/change stuff. Then i do a backup of all my selected files and folders everytime i do a retropie update. I have about 10-15 major backups.


  • Global Moderator

    @edmaul69

    Wow. If luck favors the prepared, I should be asking you for lottery numbers.



  • @mediamogul I just deleted my 2.6 backup a couple months ago. Still have all my updates after that



  • For backing up without doing a full image backup, I'd recommend looking up the rpi-clone script, provided you can plug the destination card via USB to your Pi.



  • @pjft Thanks for the info, i looked into that but it looks like i would have to have another 128gb SD card to make that work. I have a good base image for my system already saved on my computer, so my thought is that I can just copy off the folders with updates like @mediamogul has provided and then dump those back into the build once I reinstall my base image on the SD Card.

    @mediamogul, i am a little green when it comes to installing scripts, i was just going to run it from putty, but i like the idea of having the script right on the retropie menu. Forgive me for this beginner question, but do i just save the script code you posted in a .xml and then save that file to /home/pi/RetroPie/retropiemenu? That seems to easy.......Thanks


  • Global Moderator

    @TMNTturtlguy

    but do i just save the script code you posted in a .xml and then save that file to /home/pi/RetroPie/retropiemenu? That seems to easy.......Thanks

    It's just about that easy. Save it with the extension .sh and then run:

    chmod +x /home/pi/RetroPie/retropiemenu/name-of-script.sh
    

    After that it should be good to go.



Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.

Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.