All code from this tutorial as a complete package is available in this repository. If you find this tutorial helpful, please share it with your fr...
For further actions, you may consider blocking this person and/or reporting abuse
Great write up! I have one suggestion: test your backups.
Especially if you are using custom software or scripts to actually do the backup, testing that it was successful is of the utmost priority.
Speaking from experience, there is nothing worse than finding out a backup you thought you had taken actually turned out to be corrupted or broken.
Great suggestion. What's your preference for testing backups?
Since your script is just copying the files over to the destination using rsync, you can do a simple integrity test to ensure all files were copied successful.
Here's what I'd do: When your backup script is collecting the list of files to copy, hash them using something like XXHash (or any other fast non-cryptographic hashing algorithm). Record a mapping of files -> hash in a file and back that file up along with the rest.
To test the integrity, iterate over each backed up file and hash it, testing if it matches the original hash when the files was backed up.
Depending on how active the system is, you may wish to also look at using file locking (flock) to prevent writes to a file that is actively being hashed & copied.
Thank you, I really appreciate the detail of the response. I'm going to look into this and make an effort to implement it with an update so everyone can benefit. Much appreciated.
Very nice. I think an optional archive step would be a good idea to add to this - after the rsync to the output directory, tgz or zip the output folder, name the archive file suitably with a date/time, and copy to an archived directory or upload to a cloud service (perhaps encrypting also in the latter case.)
That's a REALLY good idea. If I get a chance in the next couple of days I'll definitely add that as en extra section, thank you!
Instead of hashing which might consume more memory, why not just create a txt file and place the file path and names inside...
Then when checking just compare the file path and name. This will also prevent you from using lock to lock a file too
I always end up with this error: "Backup completed with status code: 1" (I know status 1 is a syntax error or usage). Even with your piece of code, copy/paste, I have the same result.
Suggestions? 🙌
Verify the command on your terminal outside of the Node app to get more details. If you add
console.log(cmd)
inside thersync.execute
block it will print out exactly the syntax of the command that it is running in the background, so you can try running it manually.You can also add the
-v
flag to get more verbose output to troubleshootSo for example on the terminal the command using the directories from this tutorial would look like:
If you find the error and it turns out to be something others might encounter definitely let me know and I'll make an update.
I found it helpful to see the rsync command:
Nice job.💖
Great work....
Awesome