2023-11-05 18:27:48 +00:00
import sqlite3
import os
from django . core . management . base import BaseCommand
class Command ( BaseCommand ) :
help = " Creates a backup of the linkding database "
def add_arguments ( self , parser ) :
2024-01-27 10:29:16 +00:00
parser . add_argument ( " destination " , type = str , help = " Backup file destination " )
2023-11-05 18:27:48 +00:00
def handle ( self , * args , * * options ) :
2024-01-27 10:29:16 +00:00
destination = options [ " destination " ]
2023-11-05 18:27:48 +00:00
def progress ( status , remaining , total ) :
2024-01-27 10:29:16 +00:00
self . stdout . write ( f " Copied { total - remaining } of { total } pages... " )
2023-11-05 18:27:48 +00:00
2024-01-27 10:29:16 +00:00
source_db = sqlite3 . connect ( os . path . join ( " data " , " db.sqlite3 " ) )
2023-11-05 18:27:48 +00:00
backup_db = sqlite3 . connect ( destination )
with backup_db :
source_db . backup ( backup_db , pages = 50 , progress = progress )
backup_db . close ( )
source_db . close ( )
2024-01-27 10:29:16 +00:00
self . stdout . write ( self . style . SUCCESS ( f " Backup created at { destination } " ) )
2024-04-07 15:49:30 +00:00
self . stdout . write (
self . style . WARNING (
" This backup method is deprecated and may be removed in the future. Please use the full_backup command instead, which creates backup zip file with all contents of the data folder. "
)
)