This can be used to backup any directory on your computer (not just Anki). Just take care of the size of the directory you are backing up (in case it is too big you may run out of space).
Requirements:
-
MacOS, Windows or Linux with Unix environment tools
bashziprmcmpmkdirtailpsgrepawksleepxargsts(package moreutils,sudo apt-get install moreutilsorbrew install moreutils)
-
Download the following files in the same directory:
- https://evandrocoan.github.io/dotfiles/scripts/backupanki.sh (
backupanki.sh) - https://evandrocoan.github.io/dotfiles/scripts/backupankihelper.sh (
backupankihelper.sh)
- https://evandrocoan.github.io/dotfiles/scripts/backupanki.sh (
After downloading the files, edit the file backupanki.sh and replace the full path inside the variables:
export SRCDIR="...here...."by the directory where your Anki files are.export DESTDIR="...here..."by the location where you would like to save the backups.
Now, you need to schedule/configure the script backupanki.sh to run. It could be one time per day or several times:
-
On
Linuxyou can see the tutorial How to Schedule Tasks on Linux: An Introduction to Crontab Files and set it to run thebackupanki.shscript (just remember to use the full path to the script). -
On
Mac OS/Linuxyou watch the video tutorial Linux/Mac Tutorial: Cron Jobs - How to Schedule Commands with crontab and set it to run thebackupanki.shscript. -
On
Windowsyou can create a Task Scheduling task:-
Go to the Start Menu and search for
Task Scheduler -
Download the files:
- https://evandrocoan.github.io/batch_scripts/silent_run.vbs (
silent_run.vbs) - https://raw.githubusercontent.com/evandrocoan/batch_scripts/master/WindowsTaksTcheduler/AnkiBackupDailyTask.xml (
AnkiBackupDailyTask.xml)
- https://evandrocoan.github.io/batch_scripts/silent_run.vbs (
-
Edit the downloaded file
AnkiBackupDailyTask.xmland:-
Replace the full path to
silent_run.vbsby the full location of the filesilent_run.vbson your computer -
Replace the full path to
sh.exeby the full location of the filebash.exeon your computer -
Replace the full path to
backupanki.shby the full location of the filebackupanki.shon your computer
-
-
Now to go the Task Scheduler menu
Action -> Import Task...and select the fileAnkiBackupDailyTask.xml -
If you would like, you can configure the time you want to run the backup by selecting
Task Scheduler Library -> Backup Anki -> Properties -> Triggers -> Edit. -
If your computer is not on/started/running at the time you select, the backup will run automatically on the next time you start your computer after the time. You can change that by going to
Task Scheduler Library -> Backup Anki -> Properties -> Settings:
-
Notes:
-
You can see the logs of the backups by opening the file
ankibackup.logcreated automatically at the same directory where yourbackupanki.shfile is on. -
See Managing Files and Your Collection to learn where your Anki files are located. For example, on Windows this location usually is:
/cygdrive/C/Users/YourUserName/AppData/Roaming/Anki2 -
The
/cygdrive/...thing is used because on this example I am on Windows using the Unix environmentCygwinand a Windows full path asC:\Users\...has to be converted to the format/cygdrive/C/Users/.... -
If Anki is already running, the script will wait until Anki closes and then run the backup. If a new schedule of the backup run while there is an older scheduling waiting for Anki to exit, the latest scheduling will exit with error
11while the first one will still/be kept waiting for Anki to exit.
Related to:



