Bash-script to automatically back up files in a given list via git version control
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

1 år sedan
1 år sedan
1 år sedan
1 år sedan
1234567891011121314151617181920212223242526272829303132333435363738
  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. ```
  11. Create the files "backup_routine.sh" and "backup_filelist.txt" in this folder.
  12. Copy the code from "backup_routine.sh" in this repository into yours.
  13. Put the complete filepaths to the files you want to automatically be versioned into "backup_filelist.txt".
  14. Now use ```git add *``` and ```git commit -m "initial commit"```
  15. You're done setting up your automatic archive.
  16. ---
  17. ## Automation
  18. 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:
  19. ```
  20. 0,15,30,45 * * * * cd ~/Automatic\ Git\ Versioned\ Backups && sh backup_routine.sh
  21. ```
  22. This will run the script every 15 minutes.
  23. ---
  24. ## Restoration
  25. Use
  26. ```
  27. git log -- filename.ext
  28. ```
  29. to view all the past versions.
  30. Copy the commit-id of the version you wish to restore.
  31. To recreate a past version, use
  32. ```
  33. git show commit-id:filename.ext > path/to/restoration/filename.restored.ext
  34. ```
  35. For example: ```git show 8f1dc7362dd5f6781ccf9ccc5a9cfdccb57ed709:ToDo.xlsx > ToDo.restored.xlsx```