If there is an issue with the backup, you’ll not be able to get an older version. Stop overwriting filesĪs you can see in the last script, we delete the previous backup each time. “gzip” allows you to compress the whole tar file. “tar -rvf” allows you to append several files to one tar file. I add a new variable DEST_FILE to store the file name of the backup.
$BACKUP_CMD $DEST_FOLDER/$DEST_FILE /etc/app2 $BACKUP_CMD $DEST_FOLDER/$DEST_FILE /etc/app1/nf
I’ll use tar to archive all files in one and gzip to compress this file.
Most of the time, we use compression for backup or at least archive files.
The result will be the same, but it will be easier to update Compress files I’ll also do the same for the “cp” command, so if you want to change it to use rsync or another command, you’ll have only one line to edit. You’ll have to edit 200 lines in your script to change the destination folder.Ī better way to do this is to create a variable at the beginning with the destination folder path and use it for each line. The first good practice we’ll use to improve the scripts is to add variables.įor example, you have 200 files to backups to /home/pi/backups and tomorrow you want to save them in /media/nas/pi/. So now we’ll improve this script on several points. bin/cp /etc/app1/nf /home/pi/backupsĪs you can see it’s a basic script, that will overwrite the old backup each time. Then we need to create a backup folder to store the files:Īnd finally, the first version of a simple script could look like this: #!/bin/bash In my script I’ll use a file and a folder that you can adapt to your needs:
And finally, how to restore the files Scriptīefore starting to create the script, you have to identify the files you need to save.How to send the file on another computer (in the script or manually).How to schedule it if the files are modified.The first method you can use if you have a simple installation is to backup only the needed files.įor example, if you use your Raspberry Pi for a security camera, once you back up the configuration file, it’s ok, you don’t need more. If you are lost in all these new words and abbreviations, request my free Raspberry Pi glossary here (PDF format)! I’m a fan of their services personally ? Backup only the important files I highly recommend getting this offer now so that you can already learn a bunch of things in the next fortnight. It includes courses from the best teachers in many categories, including IT (Linux, programming, …) and Raspberry Pi. We will now see in detail how to do each one.īy the way, if you don’t have a budget to afford a course for now (if you just got your Raspberry Pi stuff, I completely understand), you can join Skillshare for a free 14-day trial.
Or do a full backup of a Raspberry Pi while running.Make a complete image of the SD card on another computer.Back up only important files (configuration, documents, MySQL databases).It this tutorial, I will guide you through several solutions: It highly depends on how you use your Raspberry Pi, and what is available on your network to store the backups. It’s also possible to create entire backups of the SD card, to make sure everything is secured.Īs often, there is not only one way to do this. The best way to create a backup of a Raspberry Pi is to use a tool like rsync, and copy the important files to another location on the network. Yes, but then how to backup a Raspberry Pi and recover it? That what we’ll see in this complete guide. If like me, you make many changes on your Raspberry Pi, it might be a good idea to create backups.Īnd what’s even better is to make sure backups are recoverable ?