Skip to content

Commit 47d4e41

Browse files
authored
fix(move): cli and query fixes (#45)
* fix(move): cli and query fixes * fix(cleanup): code cleanup
1 parent a67b963 commit 47d4e41

4 files changed

Lines changed: 18 additions & 8 deletions

File tree

readme.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ will be accomplished is in the integration test method [ProgressiveRestore](test
2222
You can currently use the CLI to create a copy of a database from one AG to another. It will take a log backup,
2323
then restore from the existing backup chain to the new database. If a database exists in the destination AG
2424
it will delete it and proceed with the copy.
25+
2526
```
26-
AgDatabaseMove.Cli --From:ConnectionString="Server=SourceDatabaseListener.domain.com; Integrated Security=true; MultiSubnetFailover=true;"
27-
--From:DatabaseName=sourceDbName
28-
--From:BackupPathTemplate="\\NetworkShare\{0}_backup_{1}.trn"
29-
--To:ConnectionString="Server=DestinationDatabaseListener.domain.com; Integrated Security=true; MultiSubnetFailover=true;"
30-
--To:DatabaseName=DestinationDbName
31-
--Overwrite=true
27+
AgDatabaseMove.Cli.exe
28+
--From:ConnectionString "Server=SourceDatabaseListener.domain.com; Integrated Security=true; MultiSubnetFailover=true;" --From:DatabaseName test --From:BackupPathSqlQuery "SELECT '\\NetworkShare\path\here'"
29+
--To:ConnectionString "Server=SourceDatabaseListener.domain.com; Integrated Security=true; MultiSubnetFailover=true;" --To:DatabaseName test
30+
--Overwrite true
31+
--Finalize true
32+
--CopyLogins true
33+
--DeleteSource false
3234
```
3335

3436
## Contributing

src/AgDatabaseMove.Cli/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ internal class MoveArgs
1212
public bool Overwrite { get; set; } = false;
1313
public bool Finalize { get; set; } = true;
1414
public bool CopyLogins { get; set; } = true;
15+
public bool DeleteSource { get; set; } = false;
1516
}
1617

1718
internal class Program
@@ -29,6 +30,7 @@ private static void Main(string[] args)
2930
Overwrite = arguments.Overwrite,
3031
Finalize = arguments.Finalize,
3132
CopyLogins = arguments.CopyLogins,
33+
DeleteSource = arguments.DeleteSource,
3234
FileRelocator = filename =>
3335
RestoreFileRelocator(arguments.From.DatabaseName, arguments.To.DatabaseName, filename)
3436
});

src/DatabaseConfig.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,10 @@ public class DatabaseConfig
2525
/// <example> SELECT Backup_path FROM [msdb].[dbo].[_Sys_Backup_config]</example>
2626
/// </summary>
2727
public string BackupPathSqlQuery { get; set; }
28+
29+
public override string ToString()
30+
{
31+
return $"{ConnectionString}\n{DatabaseName}\n{BackupPathSqlQuery}\n";
32+
}
2833
}
2934
}

src/SmoFacade/Server.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,13 @@ private string AgName()
6767
/// <returns>A DefaultFileLocations object which contains default log and data directories.</returns>
6868
private DefaultFileLocations DefaultFileLocations()
6969
{
70-
var query =
70+
const string query =
7171
"SELECT SERVERPROPERTY('InstanceDefaultDataPath') AS InstanceDefaultDataPath, SERVERPROPERTY('InstanceDefaultLogPath') AS InstanceDefaultLogPath";
7272

7373
using var cmd = SqlConnection.CreateCommand();
74-
using var reader = cmd.ExecuteReader();
7574
cmd.CommandText = query;
75+
using var reader = cmd.ExecuteReader();
76+
7677
if(!reader.Read())
7778
return null;
7879

0 commit comments

Comments
 (0)