mirror of
https://github.com/kevinveenbirkenbach/docker-volume-backup.git
synced 2025-07-04 15:53:09 +02:00
Added failure handling for bussy databases
This commit is contained in:
parent
7d3f0a3ae3
commit
3ed89a59a8
@ -44,14 +44,18 @@ def main():
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
for sqlfile in sql_files:
|
for sqlfile in sql_files:
|
||||||
dbname = os.path.splitext(os.path.basename(sqlfile))[0]
|
# Extract database name by stripping the full suffix '.backup.sql'
|
||||||
|
filename = os.path.basename(sqlfile)
|
||||||
|
if not filename.endswith('.backup.sql'):
|
||||||
|
continue
|
||||||
|
dbname = filename[:-len('.backup.sql')]
|
||||||
print(f"=== Processing {sqlfile} → database: {dbname} ===")
|
print(f"=== Processing {sqlfile} → database: {dbname} ===")
|
||||||
|
|
||||||
# Drop the database if it already exists
|
# Drop the database, forcing disconnect of sessions if necessary
|
||||||
run_command([
|
run_command([
|
||||||
"docker", "exec", "-i", container,
|
"docker", "exec", "-i", container,
|
||||||
"psql", "-U", "postgres", "-c",
|
"psql", "-U", "postgres", "-c",
|
||||||
f"DROP DATABASE IF EXISTS \"{dbname}\";"
|
f"DROP DATABASE IF EXISTS \"{dbname}\" WITH (FORCE);"
|
||||||
])
|
])
|
||||||
|
|
||||||
# Create a fresh database
|
# Create a fresh database
|
||||||
|
Loading…
x
Reference in New Issue
Block a user