Created
April 28, 2024 11:15
-
-
Save ahmedrowaihi/d5e45adec570eded2032de771d9ffccc to your computer and use it in GitHub Desktop.
a small script to export-import fresh mysql data ( could be used for moving dbs )
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
# Define variables | |
EC2_INSTANCE_IP = <EC2_instance_IP> | |
RDS_INSTANCE_IP = <RDS_instance_IP> | |
USERNAME = <username> | |
PASSWORD = <password> | |
DATABASE_NAME = <database_name> | |
DUMP_FILE = dump.sql | |
# Define the export and import commands | |
export: | |
@mysqldump -h $(EC2_INSTANCE_IP) -u $(USERNAME) -p$(PASSWORD) $(DATABASE_NAME) > $(DUMP_FILE) | |
import: | |
@mysql -h $(RDS_INSTANCE_IP) -u $(USERNAME) -p$(PASSWORD) $(DATABASE_NAME) < $(DUMP_FILE) | |
drop_and_import: | |
@mysql -h $(RDS_INSTANCE_IP) -u $(USERNAME) -p$(PASSWORD) $(DATABASE_NAME) -e "DROP TABLE IF EXISTS \`*\`;" | |
@mysql -h $(RDS_INSTANCE_IP) -u $(USERNAME) -p$(PASSWORD) $(DATABASE_NAME) < $(DUMP_FILE) | |
# Define the default target | |
default: export import | |
# Define a clean target to remove the dump file | |
clean: | |
@rm $(DUMP_FILE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment