![]() 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. If you want to use a different destination, you just have to update the variable at the beginning. The result will be the same, but it will be easier to update. 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, let’s say 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.Īre you a bit lost in the Linux command line? Check this article first for the most important commands to remember and a free downloadable cheat sheet so you can have the commands at your fingertips. Use sudo if needed (if the goal is to back up system files, you probably need sudo).Īs you can see, it’s a basic script, that will overwrite the old backup each time. Then add the permission to execute the script with: I’m using “/home/pi” everywhere, but you probably have to adjust this with your username (/home/pat for example).Īnd finally, the first version of a simple script could look like this: #!/bin/bash Then we need to create a backup folder to store the files: In my script, I’ll use a file and a folder that you can adapt to your needs: How to send the file to another computer (in the script or manually).īefore starting to create the script, you have to identify the files you need to save.How to schedule it if the files are modified.It’ll be the most efficient method, you don’t need to keep a 16GB image file for just this. ![]() The first method you can use if you have a simple installation is to back up 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. The first third of the book teaches you the basics, but the following chapters include projects you can try on your own. It’s a 30-day challenge where you learn one new thing every day until you become a Raspberry Pi expert. If you’re looking to quickly progress on Raspberry Pi, you can check out my e-book here. We will now see in detail how to do each one. 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. Other options are possible, like backing up only the important files to another storage drive or NAS.Īs often, there is not only one way to do this. The easiest way to create a full copy of a Raspberry Pi is to create an image of the entire SD card with a tool like SD card copier (included by default on Raspberry Pi). And what’s even better is to make sure backups are recoverable :).īut then, how to back up a Raspberry Pi and recover it? That what we’ll see in this complete guide. If, like me, you make regular changes on your Raspberry Pi, or keep important files on it, it might be a good idea to create backups. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |