Scripted Backups - which file?

I’m trying to put together a script that will automatically backup my Everdo database as a .JSON and send it to my backup hard drive, using rsync on Linux. I prefer JSON to CSV so that I can easily import it in case of recovery.

I think I can do this by copying the database file and moving it to my HD. But my question is which database file should I use under user/config/everdo ?

Have you looked at Automated Backups | Everdo Help? It might help you set up backups of the database correctly.

1 Like

Here is a Python script that you can use on Linux and Windows. It creates a backup of the running database and compresses it to a zip file.

#!/usr/bin/python3.9

from pathlib import Path
from sqlite3 import connect
from time import strftime
from zipfile import ZipFile, ZIP_DEFLATED


def backup():
    home_dir = Path.home()
    everdo_dir = home_dir / '.config' / 'everdo'
    if not everdo_dir.exists():
        everdo_dir = home_dir / 'AppData' / 'Roaming' / 'everdo'
    database_file = everdo_dir / 'db'
    if not database_file.exists():
        raise FileNotFoundError('Cannot find Everdo database')
    backup_dir = everdo_dir / 'backups'
    backup_dir.mkdir(exist_ok=True)
    dt = strftime("%Y-%m-%d_%H-%M-%S")
    backup_name = f'db_backup_{dt}.sqlite'
    backup_file = backup_dir / backup_name
    database = connect(database_file)
    backup = connect(backup_file)
    database.backup(backup)
    backup.close()
    database.close()
    zip_file = backup_file.with_suffix('.zip')
    with ZipFile(zip_file, 'w', ZIP_DEFLATED) as zf:
        zf.write(backup_file, backup_name)
    backup_file.unlink()


if __name__ == '__main__':
    backup()
1 Like

Yes I have, however this script exports as .sqlite. Forgive my ignorance but I believe we can only import .csv and .json into Everdo?

To restore the backup you simple replace the file named db in the data directory with the backup file, renaming it.

Oh nice, that makes things easy.

P.S. I am LOVING this application!

Does anyone know how I can replace the old backup with the new one?

I’ve got my script 99.9% done. I’ll share it when it’s finished.

The only missing step is to delete the old backup. This would be easy to do if the backup had a static name, but alas, we’re a dilligent bunch here and want to keep the time and date in the filename.

You can use something like rotate-backups to implement a rotation scheme for older backups.

Thanks everybody but I’ve finished this project. I have one unified backup script that backs up Everdo, Firefox bookmarks, and then copies the home directory to my external hard drive.

For Everdo this is what I have:

`#delete old Everdo backups
cd Documents/Backups
rm everdo_backup_*
cd

#create Timestamp
TIMESTAMP=$(date +%F_%T | tr ':' '-')

#backup Everdo
sqlite3 /home/user/.config/everdo/db ".backup '/home/user/Documents/Backups/everdo_backup_$TIMESTAMP.sqlite'"`

The only flaw could be that I delete all Everdo backups first, which could leave me back-up-less if the next backup fails. But, I don’t think that’s an issue since I must have access to the computer to run this, so I can most definitely still create a new backup.