Bash-script to automatically back up files in a given list via git version control
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2 年之前
2 年之前
2 年之前
123456789101112131415161718192021222324252627282930313233343536373839
  1. This script checks if changes happened to a given list of files, and if so, it'll store them into a next version as back up.
  2. ## Setup
  3. Install git.
  4. Create a folder that should act as your automatic archive.
  5. Open that folder with your terminal and execute ```git init```
  6. Create a file in the folder called ".gitignore" and put the following in it:
  7. ```
  8. backup_routine.sh
  9. backup_filelist.txt
  10. log.txt
  11. ```
  12. Create the files "backup_routine.sh" and "backup_filelist.txt" in this folder.
  13. Copy the code from "backup_routine.sh" in this repository into yours.
  14. Put the complete filepaths to the files you want to automatically be versioned into "backup_filelist.txt".
  15. Now use ```git add *``` and ```git commit -m "initial commit"```
  16. You're done setting up your automatic archive.
  17. ---
  18. ## Automation
  19. Make it so that "sh backup_routine.sh" gets called automatically. I recommend setting up a cron job, for example by executing ```EDITOR=nano crontab -e``` and writing the following into crontab:
  20. ```
  21. 0,15,30,45 * * * * cd ~/Automatic\ Git\ Versioned\ Backups && sh backup_routine.sh
  22. ```
  23. This will run the script every 15 minutes.
  24. ---
  25. ## Restoration
  26. Use
  27. ```
  28. git log -- filename.ext
  29. ```
  30. to view all the past versions.
  31. Copy the commit-id of the version you wish to restore.
  32. To recreate a past version, use
  33. ```
  34. git show commit-id:filename.ext > path/to/restoration/filename.restored.ext
  35. ```
  36. For example: ```git show 8f1dc7362dd5f6781ccf9ccc5a9cfdccb57ed709:ToDo.xlsx >> ToDo.restored.xlsx```