This is a simple script to automatically backup your Obsidian vault to a git repository. It is written in batch script and intended to be used on Windows.
- Clone this repository to your computer.
git clone [email protected]:MetinUsta/Obsidian-Auto-Backup.git
-
Create a new repository on GitHub. You can skip to step 5 if you already have a repository connected to your Obsidian vault.
-
Create a local git repository in your Obsidian vault.
cd /path/to/your/vault
git init -b main # or any name you want
- Add the remote repository to your local repository.
git remote add origin <your-repository-url>
- Modify the 'obsidian_auto_backup.bat' file, specifically the following lines:
line 11: cd "PATH/TO/YOUR/OBSIDIAN/VAULT"
line 42: git push origin <YOUR BRANCH NAME> > NUL 2>&1
There are different ways to use this script:
-
Run the script manually by double-clicking on the 'obsidian_auto_backup.bat' file.
-
Run the script automatically by creating a scheduled task on Windows Task Scheduler.
-
Run the script automatically by installing the "Shell Commands" plugin on Obsidian and creating a new command.
-
This script will add all the files in your Obsidian vault to the git repository. If you want to exclude some files, you can add them to a '.gitignore' file or modify the script.
-
This script will use date and time as the commit message. If you want to change the commit message, you can modify the script.
- When using "Shell Commands" plugin on Obsidian, you can prompt the user to enter a commit message. Later, you can use this commit message in the script.
- There may be some errors with date and time parsing since the script is locale dependent. It is recommended to use the script with English locale.
-
When using "Shell Commands" plugin on Obsidian, if you set the output channel for stdout as "Notification balloon" you will see messages related to the individual steps of the script.
- e.g.
Found changes Commit successful. Push successful.
It will look like below:
-
When using "Shell Commands" plugin on Obsidian, be careful with the triggering events. If you set the trigger as "Obsidian quits", the execution of the script may be halted. Also be sure not to select a frequently triggered event since it may cause some performance issues.
- "Obsidian starts" and "Every n seconds" with high second value (e.g. 300, 600) seem reasonable.
- You can also set a hotkey for the command and run it manually. I set it as "Ctrl + Alt + S".
Pull requests are welcome. If you have any questions feel free to open an issue about it.