usr/local/bin/restic backup -verbose -o b2.connections = 20 -files-from ~/backup.txtĮcho $(date + "%Y-%m-%d %T" ) "Backup finished" echo $(date -v +6H + "%s" ) > $TIMESTAMP_FILE Rm $PID_FILE fi fi if then time_run = $(cat " $TIMESTAMP_FILE " ) current_time = $(date + "%s" ) if then exit 2 fi fi if ] then echo $(date + "%Y-%m-%d %T" ) "Unsupported network." exit 3 fi if ] then echo $(date + "%Y-%m-%d %T" ) "Computer is not connected to the power source." exit 4 fi echo $$ > $PID_FILE echo $(date + "%Y-%m-%d %T" ) "Backup start" export B2_ACCOUNT_ID = $(security find-generic-password -s backup-restic-b2-accound-id -w ) export B2_ACCOUNT_KEY = $(security find-generic-password -s backup-restic-b2-account-key -w ) export RESTIC_REPOSITORY = $(security find-generic-password -s backup-restic-repository -w ) export RESTIC_PASSWORD_COMMAND = 'security find-generic-password -s backup-restic-password-repository -w' Probably backup is already in progress." exit 1 else echo $(date + "%Y-%m-%d %T" ) "File $PID_FILE exist but process " $(cat $PID_FILE ) " not found. If then if ps -p $(cat $PID_FILE ) > /dev/null then echo $(date + "%Y-%m-%d %T" ) "File $PID_FILE exist. TIMESTAMP_FILE =~/.restic_backup_timestamp Let’s keep it simple and use the file as we do with the PID file. Add time condition to your scriptįirst, you need to have an additional place to store the timestamp. I’m going to show you how to add this kind of logic into the backup script. For short intervals, like 5 minutes, everything works like a charm.īacking up files every 5 minutes is too aggressive and surely not needed, because it leads to many snapshots of data with small differences. The job will be executed after an unpredictable time, sometimes much later than the interval value. I’ve experienced also another issue related to the StartInterval property, especially if the value is greater than a few hours. Despite that, launchd get the information that script was executed and it will schedule the next execution and you end up with no backup. Nevertheless, the script has some extra conditions that may break the execution earlier – this is a variation of the return early approach. In macOS, the easiest way to do is to using homebrew. Install resticįirst, you need to install restic. It means you are not limited to browse files only within directories, but also in different moments in time. Thanks to restic and your perseverance to organize files, you’ll add extra dimension of your disk – time. If you have a dedicated place on the disk for stuff you care, you’ll never have a problem with finding the file you lost or need. Maintaining a good and solid file structure may help you also during restoring files from snapshots. Keep files you want to backup and non-important files separate. Are you need to backup your entire disk? Do you want to pay for storing all these downloaded stuff? Preparing environment Make your file structure backup-friendlyīefore you start, I recommend you to clean up the disk a little bit by separating stuff you care from the clutter you don’t need. Bash – I’m going to write the script in bash.macOS keychain – secure way to store secrets.launchd – macOS’s system service management (you can use cron).Backblaze B2 – Cloud storage (you can use a different provider).Restic – a command-line tool for creating backups and restoring files.If you want to know more, please check the documentation of these tools. I’ll describe how to use them in the context of creating the backup script. In this article, I’m going to use some tools and services and I assume, that you have basic knowledge of them. Start with the minimal script and change when you notice that you need something more. Trying to build something perfect first off will lead to a product with unnecessary features. I use a word process, because it’s not a single task. Instead, I’ll show you my process of building the backup script that works for me. You should always adjust the tools and the workflow to your needs. I know nothing about your needs, your files, limitations of your network, budget, and other things that could have an impact on the backup workflow. I’m not going to give you a ready-to-use script or working solution. Even though the article is specific for macOS and Backblaze B2, you can use some techniques for creating a similar script for Linux systems. In this article, I would like to show you how to prepare the script that will back up your important files to the cloud storage using a tool called restic.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |