-
-
Notifications
You must be signed in to change notification settings - Fork 593
dolthub/dolt#10136: Fix dolt_backup to work in non-Dolt directories
#10164
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
Open
elianddb
wants to merge
2
commits into
main
Choose a base branch
from
elian/10136
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -7,15 +7,16 @@ setup() { | |
| } | ||
|
|
||
| teardown() { | ||
| stop_sql_server | ||
| teardown_common | ||
| } | ||
|
|
||
| @test "sql-backup: dolt_backup no argument" { | ||
| run dolt sql -q "call dolt_backup()" | ||
| [ "$status" -ne 0 ] | ||
| [[ "$output" =~ "use 'dolt_backups' table to list backups" ]] || false | ||
| run dolt sql -q "CALL dolt_backup()" | ||
| [ "$status" -ne 0 ] | ||
| [[ "$output" =~ "use 'dolt_backups' table to list backups" ]] || false | ||
| } | ||
|
|
||
| @test "sql-backup: dolt_backup add" { | ||
|
|
@@ -28,16 +29,16 @@ teardown() { | |
| } | ||
|
|
||
| @test "sql-backup: dolt_backup add cannot add remote with address of existing backup" { | ||
| mkdir bac1 | ||
| dolt sql -q "call dolt_backup('add','bac1','file://./bac1')" | ||
| run dolt sql -q "call dolt_backup('add','rem1','file://./bac1')" | ||
| backupFileUrl="file://$BATS_TEST_TMPDIR/backup" | ||
| dolt sql -q "call dolt_backup('add','bac1', '$backupFileUrl')" | ||
| run dolt sql -q "call dolt_backup('add','rem1', '$backupFileUrl')" | ||
| [ "$status" -eq 1 ] | ||
| [[ "$output" =~ "address conflict with a remote: 'bac1'" ]] || false | ||
| } | ||
|
|
||
| @test "sql-backup: dolt_backup remove" { | ||
| mkdir bac1 | ||
| dolt sql -q "call dolt_backup('add', 'bac1', 'file://./bac1')" | ||
| backupFileUrl="file://$BATS_TEST_TMPDIR/backup" | ||
| dolt sql -q "call dolt_backup('add', 'bac1', '$backupFileUrl')" | ||
| run dolt backup -v | ||
| [ "$status" -eq 0 ] | ||
| [ "${#lines[@]}" -eq 1 ] | ||
|
|
@@ -61,8 +62,8 @@ teardown() { | |
| } | ||
|
|
||
| @test "sql-backup: dolt_backup rm" { | ||
| mkdir bac1 | ||
| dolt sql -q "call dolt_backup('add', 'bac1', 'file://./bac1')" | ||
| backupFileUrl="files://$BATS_TEST_TMPDIR/backup" | ||
| dolt sql -q "call dolt_backup('add', 'bac1', '$backupFileUrl')" | ||
| run dolt backup -v | ||
| [ "$status" -eq 0 ] | ||
| [ "${#lines[@]}" -eq 1 ] | ||
|
|
@@ -93,18 +94,18 @@ teardown() { | |
| } | ||
|
|
||
| @test "sql-backup: dolt_backup restore" { | ||
| backupsDir="$PWD/backups" | ||
| backupFileUrl="file://$BATS_TEST_TMPDIR/backups" | ||
| mkdir backupsDir | ||
|
|
||
| # Created a nested database, back it up, drop it, then restore it with a new name | ||
| dolt sql -q "create database db1;" | ||
| cd db1 | ||
| dolt sql -q "create table t1 (pk int primary key); insert into t1 values (42); call dolt_commit('-Am', 'creating table t1');" | ||
| dolt sql -q "call dolt_backup('add', 'backups', 'file://$backupsDir');" | ||
| dolt sql -q "call dolt_backup('add', 'backups', '$backupFileUrl');" | ||
| dolt sql -q "call dolt_backup('sync', 'backups');" | ||
| cd .. | ||
| dolt sql -q "drop database db1;" | ||
| dolt sql -q "call dolt_backup('restore', 'file://$backupsDir', 'db2');" | ||
| dolt sql -q "call dolt_backup('restore', '$backupFileUrl', 'db2');" | ||
|
|
||
| # Assert that db2 is present, and db1 is not | ||
| run dolt sql -q "show databases;" | ||
|
|
@@ -124,33 +125,53 @@ teardown() { | |
| [ "${#lines[@]}" -eq 0 ] | ||
| } | ||
|
|
||
| @test "sql-backup: dolt_backup restore --force" { | ||
| backupsDir="$PWD/backups" | ||
| mkdir backupsDir | ||
| @test "sql-backup: dolt_backup restore --force on current database" { | ||
| backupFileUrl="file://$BATS_TEST_TMPDIR/backups" | ||
|
|
||
| # Created a nested database, and back it up | ||
| dolt sql -q "create database db1;" | ||
| cd db1 | ||
| dolt sql -q "create table t1 (pk int primary key); insert into t1 values (42); call dolt_commit('-Am', 'creating table t1');" | ||
| dolt sql -q "call dolt_backup('add', 'backups', 'file://$backupsDir');" | ||
| dolt sql -q "call dolt_backup('sync', 'backups');" | ||
| # We could cd into db1 but Windows does not like us touching its CWD when we drop the database when restoring. | ||
| dolt sql -q "use db1; create table t1 (pk int primary key); insert into t1 values (42); call dolt_commit('-Am', 'creating table t1');" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. worth noting you can: That's more characters I guess :) |
||
| dolt sql -q "use db1; call dolt_backup('add', 'backups', '$backupFileUrl');" | ||
| dolt sql -q "use db1; call dolt_backup('sync', 'backups');" | ||
|
|
||
| # Make a new commit in db1, but don't push it to the backup | ||
| dolt sql -q "update t1 set pk=100; call dolt_commit('-Am', 'updating table t1');" | ||
| dolt sql -q "use db1; update t1 set pk=100; call dolt_commit('-Am', 'updating table t1');" | ||
|
|
||
| # Assert that without --force, we can't update an existing db from a backup | ||
| run dolt sql -q "call dolt_backup('restore', 'file://$backupsDir', 'db1');" | ||
| run dolt sql -q "use db1; call dolt_backup('restore', '$backupFileUrl', 'db1');" | ||
| [ "$status" -eq 1 ] | ||
| [[ "$output" =~ "database 'db1' already exists, use '--force' to overwrite" ]] || false | ||
|
|
||
| # Use --force to overwrite the existing database and sanity check the data | ||
| run dolt sql -q "call dolt_backup('restore', '--force', 'file://$backupsDir', 'db1');" | ||
| run dolt sql -q "use db1; call dolt_backup('restore', '--force', '$backupFileUrl', 'db1');" | ||
| [ "$status" -eq 0 ] | ||
| run dolt sql -q "use db1; select * from t1;" | ||
| [ "$status" -eq 0 ] | ||
| [[ "$output" =~ "42" ]] || false | ||
| } | ||
|
|
||
| @test "sql-backup: dolt_backup restore --force on current database and as cwd" { | ||
| skiponwindows "Windows storage system locks the terminal cwd when trying to drop database in restore procedure; this includes mounted storage in WSL" | ||
| backupFileUrl="file://$BATS_TEST_TMPDIR/backup" | ||
| dolt sql -q "create database db1;" | ||
| cd db1 | ||
| dolt sql <<EOF | ||
| create table t (i int); | ||
| insert into t values (3), (4); | ||
| call dolt_backup('sync-url', '$backupFileUrl'); | ||
| EOF | ||
|
|
||
| run dolt sql -q "call dolt_backup('restore', '$backupFileUrl', 'db1');" | ||
| [ "$status" -eq 1 ] | ||
| [[ "$output" =~ "database 'db1' already exists, use '--force' to overwrite" ]] || false | ||
|
|
||
| run dolt sql -q "call dolt_backup('restore', '--force', '$backupFileUrl', 'db1');" | ||
| [ "$status" -eq 0 ] | ||
| run dolt sql -q "select * from t;" | ||
| [[ "$output" =~ i.*3.*4 ]] || false | ||
| } | ||
|
|
||
| @test "sql-backup: dolt_backup unrecognized" { | ||
| run dolt sql -q "call dolt_backup('unregonized', 'hostedapidb-0', 'file:///some_directory')" | ||
| [ "$status" -ne 0 ] | ||
|
|
@@ -177,37 +198,31 @@ teardown() { | |
| } | ||
|
|
||
| @test "sql-backup: dolt_backup sync to a backup" { | ||
| mkdir the_backup | ||
| dolt backup add hostedapidb-0 file://./the_backup | ||
| backupFileUrl="file://$BATS_TEST_TMPDIR/the_backup" | ||
| dolt backup add hostedapidb-0 "$backupFileUrl" | ||
| dolt backup -v | ||
| dolt sql -q "call dolt_backup('sync', 'hostedapidb-0')" | ||
| # Initial backup works. | ||
| dolt backup restore file://./the_backup the_restore | ||
| dolt backup restore "$backupFileUrl" the_restore | ||
| (cd the_restore && dolt status) | ||
| # Backup with nothing to push works. | ||
| dolt sql -q "call dolt_backup('sync', 'hostedapidb-0')" | ||
|
|
||
| rm -rf the_backup the_restore | ||
|
|
||
| mkdir the_backup | ||
| dolt sql -q "CALL dolt_backup('sync', 'hostedapidb-0')" | ||
| dolt backup restore file://./the_backup the_restore | ||
| dolt backup restore "$backupFileUrl" the_restore --force | ||
| (cd the_restore && dolt status) | ||
| dolt sql -q "CALL dolt_backup('sync', 'hostedapidb-0')" | ||
| } | ||
|
|
||
| @test "sql-backup: dolt_backup sync-url" { | ||
| mkdir the_backup | ||
| dolt sql -q "call dolt_backup('sync-url', 'file://./the_backup')" | ||
| backupFileUrl="file://$BATS_TEST_TMPDIR/the_backup" | ||
| dolt sql -q "call dolt_backup('sync-url', '$backupFileUrl')" | ||
| # Initial backup works. | ||
| dolt backup restore file://./the_backup the_restore | ||
| dolt backup restore "$backupFileUrl" the_restore | ||
| (cd the_restore && dolt status) | ||
|
|
||
| rm -rf the_backup the_restore | ||
|
|
||
| mkdir the_backup | ||
| dolt sql -q "CALL dolt_backup('sync-url', 'file://./the_backup')" | ||
| dolt backup restore file://./the_backup the_restore | ||
| dolt sql -q "CALL dolt_backup('sync-url', '$backupFileUrl')" | ||
| dolt backup restore "$backupFileUrl" the_restore --force | ||
| (cd the_restore && dolt status) | ||
| } | ||
|
|
||
|
|
@@ -219,6 +234,7 @@ teardown() { | |
| } | ||
|
|
||
| @test "sql-backup: dolt_backup rejects AWS parameters fails in sql-server" { | ||
| skip_if_remote | ||
| start_sql_server | ||
|
|
||
| run dolt sql -q "call dolt_backup('add', 'backup1', 'aws://[table:bucket]/db', '--aws-region=us-east-1')" | ||
|
|
@@ -236,4 +252,27 @@ teardown() { | |
| run dolt sql -q "call dolt_backup('add', 'backup4', 'aws://[table:bucket]/db', '--aws-creds-profile=profile')" | ||
| [ "$status" -eq 1 ] | ||
| [[ "$output" =~ "AWS parameters are unavailable when running in server mode" ]] || false | ||
|
|
||
| stop_sql_server 1 | ||
| } | ||
|
|
||
| @test "sql-backup: dolt_backup works in invalid dolt repository" { | ||
| backupFileUrl="file://$BATS_TEST_TMPDIR/t_backup" | ||
| run dolt sql -q "create table t (i int);" | ||
| [ "$status" -eq 0 ] | ||
| run dolt sql -q "insert into t values (4), (3);" | ||
| [ "$status" -eq 0 ] | ||
| run dolt sql -q "call dolt_backup('sync-url', '$backupFileUrl')" | ||
| [ "$status" -eq 0 ] | ||
|
|
||
| invalidRepoDir="$BATS_TEST_TMPDIR/invalid_repo" | ||
| mkdir -p "$invalidRepoDir" | ||
| cd $invalidRepoDir | ||
| dolt sql -q "call dolt_backup('restore', '$backupFileUrl', 't_db')" | ||
| [ "$status" -eq 0 ] | ||
|
|
||
| cd t_db | ||
| run dolt sql --result-format csv -q "select * from t" | ||
| [ "$status" -eq 0 ] | ||
| [[ "$output" =~ i.*3.*4 ]] || false | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sql-clientisn't a thing anymore. that's dead code.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More generally, I think we to leave this set as is. the backup restore case is not special enough to be added to this list. I don't see
clonehere. Why not? This list and it's contents seems. Going to DM you about this.