#!/bin/bash

sql_dump_script = ".output
.dump
.exit"

cd /app/var
for db in *.db
do
    basename=$(echo "$db" | sed "s/\.db$//" | sed "s/\s/_/g")
    timestamp=$(date +%Y-%m-%dT%H-%M-%S.%N)
    echo "$sql_dump_script" \
        | sqlite3 "$db" \
        > "backups/${basename}_dump_${timestamp}.sql"
done
