Puzzle pat patrouille

Comment

Author: Admin | 2025-04-28

Following, I’ll show you :How to create a script to do that.How to schedule it if the files are modified.How to send the file to another computer (in the script or manually).And finally, how to restore the files.Note: If you want to see all these steps in action, I have a video lesson available for the community members. You can join here and watch it directly if you are interested (with 20+ other lessons for Raspberry Pi and many other benefits).ScriptBefore starting to create the script, you have to identify the files you want to save. In my example below, I’ll use “app1” as a specific app I want and “file1.conf” as its configuration. The folder “app2” represents another app I want to back up. Adapt these locations in my script to your needs:/etc/app1/file1.conf/etc/app2Next, we’ll need to create a folder to store the backups:mkdir /home/pat/backupsNote: I’m using “/home/pat” everywhere, but you probably have to adjust this to match your username (i.e., /home/tom). Use sudo with the commands below if needed (if the goal is to back up system files, you probably need sudo).Okay, now let’s use nano to create the script:nano /usr/local/bin/backup.shAnd finally, the first version of a simple script could look like this:#!/bin/bash/bin/cp /etc/app1/file1.conf /home/pat/backups/bin/cp /etc/app2 /home/pat/backups/ -rSave your changes and exit nano.Then add the permission to execute the script with:chmod +x /usr/local/bin/backup.shAnd you can try it with:/usr/local/bin/backup.shAs you can see, it’s a basic script, that will overwrite the old backup each time.Next, let’s see how we can improve this script on several points.Are 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 VariablesThe first good practice we’ll use to improve the scripts is to add variables.For example, let’s say you have 200 files to back up to /home/pat/backups, but tomorrow you want to save them in /media/nas/pat/ instead. You’ll have to edit 200 lines in your script to change the destination folder. Not that smart.A better way to do this is to

Add Comment