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
bash
zip
rm
cmp
mkdir
tail
ps
grep
awk
sleep
xargs
ts
(package moreutils,sudo apt-get install moreutils
orbrew 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
Linux
you can see the tutorial How to Schedule Tasks on Linux: An Introduction to Crontab Files and set it to run thebackupanki.sh
script (just remember to use the full path to the script). -
On
Mac OS/Linux
you watch the video tutorial Linux/Mac Tutorial: Cron Jobs - How to Schedule Commands with crontab and set it to run thebackupanki.sh
script. -
On
Windows
you 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.xml
and:-
Replace the full path to
silent_run.vbs
by the full location of the filesilent_run.vbs
on your computer -
Replace the full path to
sh.exe
by the full location of the filebash.exe
on your computer -
Replace the full path to
backupanki.sh
by the full location of the filebackupanki.sh
on 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.log
created automatically at the same directory where yourbackupanki.sh
file 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 environmentCygwin
and 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
11
while the first one will still/be kept waiting for Anki to exit.
Related to: