-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
81e74ee
commit 3adcb7b
Showing
11 changed files
with
2,076 additions
and
1,682 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/bash | ||
|
||
if [ -f .env ]; then | ||
export $(cat .env | xargs) | ||
fi | ||
|
||
|
||
# Get the list of tables | ||
TABLES=$(mysql -u"$DB_USER" -p"$DB_PASSWORD" -D"$DB_NAME" -Bse "SHOW TABLES") | ||
|
||
# Loop through tables and generate TRUNCATE statements | ||
for TABLE in $TABLES; do | ||
echo "TRUNCATE TABLE \`$TABLE\`;" >> truncate_tables.sql | ||
done | ||
|
||
# Print message indicating that the SQL file has been generated | ||
echo "SQL script 'truncate_tables.sql' has been generated." | ||
|
||
# Optionally, execute the script | ||
mysql -u"$DB_USER" -p"$DB_PASSWORD" -D"$DB_NAME" < truncate_tables.sql | ||
|
||
# Step 4: Export the database to a file | ||
echo "Exporting database to '$EXPORT_FILE'..." | ||
|
||
mysqldump -u"$DB_USER" -p"$DB_PASSWORD" "$DB_NAME" > "$EXPORT_FILE" | ||
|
||
# Print message indicating that the export is complete | ||
echo "Database export completed. The dump file is '$EXPORT_FILE'." |
Oops, something went wrong.