Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database Export #285

Open
AnalogJ opened this issue Oct 19, 2023 · 2 comments
Open

Database Export #285

AnalogJ opened this issue Oct 19, 2023 · 2 comments

Comments

@AnalogJ
Copy link
Member

AnalogJ commented Oct 19, 2023

It would be nice if there was a commandline flag to safely export the database:

  • ensure all transactions have completed
  • flush the WAL
  • VACUUM the database

Until that's completed, users can use this backup script provided by @OhHeyAlan:

#!/bin/bash

#Make a Bash Script Executable
# chmod +x /root/save_db.sh
#edits crontab entries to add, delete, or edit cron jobs.
# crontab -e

# Function to copy a directory and rename it based on certain conditions.
copyAndRenameDirectory() {
    source_dir="/home/ubuntu/containers/fasten-main/fasten"  # Path to the source directory.
    destination_dir="/home/ubuntu/containers/fasten-main/mainDBsaved"  # Path to the destination directory.
    current_date=$(date +"%Y-%m-%d")  # Get the current date.
    last_23_hours=$(date -d "23 hours ago" +%s)  # Get the time 23 hours ago in seconds.
    new_name="phr_main_${current_date}"

    # Check if the source directory exists and is not empty.
    if [ ! -d "$source_dir" ] || [ -z "$(ls -A "$source_dir")" ]; then
        echo "Source directory does not exist or is empty."
        exit 1
    fi

    # Check if the destination directory exists.
    if [ ! -d "$destination_dir" ]; then
        echo "Destination directory does not exist."
        exit 1
    fi

    # Check if the new file already exist.
    if [ -d "$destination_dir/$new_name" ]; then
        echo "Directory already exist."
        exit 1
    fi

    # Check if the new file already exist.
    if [ -f "$destination_dir/$new_name" ]; then
        echo "Daily file already exist."
        exit 1
    fi

    # Check if there are any files in the source directory that were modified in the last 23 hours.
    for file in "$source_dir"/*; do
        if [ -f "$file" ] && [ $(stat -c %Y "$file") -gt "$last_23_hours" ]; then
            # Copy the entire source directory to the destination and rename it.
            new_name="phr_main_${current_date}"
            cp -r "$source_dir" "$destination_dir/$new_name"
            echo "Directory copied and renamed successfully: $new_name"
            exit 0
        fi
    done

    echo "No changes in the source directory within the last 23 hours. Skipping copy."
}

copyAndRenameDirectory
@AnalogJ
Copy link
Member Author

AnalogJ commented Dec 4, 2023

related #330

Flush/Truncate the database WAL on app shutdown.

    PRAGMA wal_checkpoint(TRUNCATE);

@nicholasburka
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants