Jump to content

Coding

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by PayPalHoneyExposed (talk | contribs) at 07:00, 26 December 2024. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Coding may refer to: import sqlite3 import shutil

  1. Database file paths

source_db_file = 'source.db' backup_db_file = 'backup.db'

  1. Function to create a backup of the SQLite database

def backup_database():

   try:
       shutil.copy2(source_db_file, backup_db_file)
       print("Backup successful.")
   except Exception as e:
       print(f"Backup failed: {str(e)}")
  1. Function to restore the SQLite database from a backup

def restore_database():

   try:
       shutil.copy2(backup_db_file, source_db_file)
       print("Restore successful.")
   except Exception as e:
       print(f"Restore failed: {str(e)}")
  1. Usage

while True:

   print("Options:")
   print("1. Backup Database")
   print("2. Restore Database")
   print("3. Quit")
   choice = input("Enter your choice (1/2/3): ")
   if choice == '1':
       backup_database()
   elif choice == '2':
       restore_database()
   elif choice == '3':
       break
   else:
       print("Invalid choice. Please enter 1, 2, or 3.")

Computer science

Other uses

See also