Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
tracking/backup.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
25 lines (21 sloc)
780 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import shutil | |
import os | |
import datetime | |
import sqlite3 | |
# Set the path to the database file | |
db_path = 'C:/Users/anuja/PycharmProjects/logisticstracking/tracking.db' | |
# Set the path to the backup directory | |
backup_dir = 'C:/Users/anuja/PycharmProjects/logisticstracking' | |
# Create the backup directory if it doesn't exist | |
if not os.path.exists(backup_dir): | |
os.makedirs(backup_dir) | |
# Set the backup file name with timestamp | |
backup_file = backup_dir + 'backup_' + datetime.datetime.now().strftime('%Y%m%d_%H%M%S') + 'tracking.db' | |
# Connect to the database | |
conn = sqlite3.connect(db_path) | |
# Create a cursor object | |
cursor = conn.cursor() | |
# Make a copy of the database file | |
shutil.copyfile(db_path, backup_file) | |
# Close the database connection | |
conn.close() |