After running the up command, my database doesn't seem to be recognizing the SQL contained inside relative/path/000001_init_schema.up.sql.
So far:
Verified I have a connection to the database
Successfully executed the SQL inside my database manager (TablePlus)
Relative path is correct (-path db/migration)
Full command:
migrate -path relative/path -database "postgresql://root:secret#localhost:5432/dbname?sslmode=disable" -verbose up
After running the command, I receive confirmation that "no changes have been made", but my database only has a schema_migrations table.
Any other ideas?
Thanks,
Connor
I solved the issue by replacing -path relative/path with -source file://relative/path
Alternatively, you can use -source file:///absolute/path
Related
I have been looking for the powershell commands for getting the backup path of a database in an sql server. I would be providing sever name and database name as input. Could some one help me with the solution so that I can achieve my requirement.
Note: I just need the path of the database backup. I need not to do any back up of that database in a path.
Thanks in advance.
Sudhir
So.... couple of things.
A SQL Server instance (sounds like you're asking about SQL Server), has a default backup location, which can be overridden at the time of a backup. If you want to see an instance's default backup location, I'd use something like this:
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo")
$i = New-Object 'Microsoft.SqlServer.Management.Smo.Server' '(local)'
$i.Settings.BackupDirectory
I'm using SQL Server Management Objects (SMO) here. I've created an instance object ($i), and I've queried the BackupDirectory property in the Settings collection to get the desired path.
If you don't like SMO, you can also get this information from the registry; see this article for help there.
Adding an answer here (since I can't add comments yet), there is also the option to use the newer SQLServer module in powershell. Just run a query to get the data you need. This is for a local SQL Express instance, update the name as needed.
Import-Module SqlServer
$bkppath = Invoke-Sqlcmd -Query "SELECT SERVERPROPERTY('InstanceDefaultBackupPath')" -ServerInstance ".\SQLExpress"
$bkppath.Column1
As an added bonus, if you'd like to delete the oldest backups just run this line, updating the best number of days to keep (AddDays function) (using bits of Pinal code from https://blog.sqlauthority.com/2018/04/02/sql-server-powershell-script-delete-old-backup-files-in-sql-express/ ):
Get-ChildItem $bkppath.Column1 -Recurse | Where-Object { $_.LastWriteTime -lt (Get-Date).AddDays(-7) } | Remove-Item -Recurse
I am trying to move a subsite of 100Gb by using Export and import commands. But I am getting error when I try this command
Export-SPWeb http://dc/sites/Coms –Path "//servername/W$Backups/cops.cmp" -IncludeVersions ALL -includeusersecurity
In the above command W is the Drive name and Backups is the folder name in that server. Can anyone help? Is this correct or is there any solution? Thanks
Are yo trying to store backup in some other server? In no, then your syntax should be like follow:
Export-SPWeb http://dc/sites/Coms –Path "W:\Backups\cops.cmp" -IncludeVersions ALL -includeusersecurity
Please refer this MSDN link on export web if you want any more guidance on it:
https://technet.microsoft.com/en-us/library/ff607895.aspx
I've created azure database using powershell. Now i want to rename the database using powershell. My purpose to do this is creating temporary database, then deploy database release to temp DB,then rename production db to any other name, finaly rename Temp Db to production db
To achieve this, you can use the cmdlet "Set-AzureSqlDatabase", the parameter "-NewDatabaseName" permits to set a new name for a specified database name.
Set-AzureSqlDatabase -ServerName 'myservername' -DatabaseName 'mydb' -NewDatabaseName 'newNameForTheDb'
Here is the documentation : https://msdn.microsoft.com/fr-fr/library/dn546732.aspx
using Az.Sql module the command command would be:
Set-AzSqlDatabase -DatabaseName <sourceDbName> -NewName <targetDbName> -ServerName <server1> -ResourceGroupName <resgroup1>
I was creating a Full and differential backup of a web application with Backup-SPFarm command. Backup thing is working fine for me.
Can anyone have idea how to restore this full backup to a new web application with Restore-SPFarm command ?
I have tried with powershell and SharePoint central administration, but no success and it is not giving any error as well it saying it is successfully completed.
Using these commands for backup and restore
Backup-SPFarm -Directory 'c:\bkp' -BackupMethod full -Item 'SharePoint - 80' -Verbose
Restore-SPFarm -Directory C:\bkp -RestoreMethod Overwrite -Item "SharePoint - 41434" -BackupId e7e7b9a5-355e-4f6c-b340-c453274b129a -Verbose
Anyone have any idea ?
Thanks
Have you checked the restore-log? Are you restoring it to the same server/environment? I'm not sure you can restore it to the same servers since the content-database will be the same. Have you tried to restore it to a dev-environment?
I have a Powershell script that uses invoke-sqlcmd to apply scripts to a series of development databases. I loop through a list of scripts and compare it to the current release level of the database and then apply the required scripts to get the DB to the release level it needs to be at. Certain databases are reference databases and are in a READ_ONLY state. I connect to those database run an alter DB script setting them to READ_WRITE apply the script then change the back to READ_ONLY. Overall the script works well, the issue is it looks like when PowerShell first opens a connection to the database and applies the first script and then goes to alter the DB back to READ_ONLY the database has objects locked. I've traced it back to the previous connection and a Shared_Transaction_Workspace lock (sys.dm_tran_locks) for what looks to be the previous powershell connection. Why is this connection still open after the invoke-sqlcmd has completed and is there anything I can do about it? Can I force invoke-sqlcmd to use a new connection for each invocation of the cmdlet?
I have tried a messy fix killing the offending connection and then retrying the connection but I think there is something better.
I've always done this and it seems to work:
[System.Data.SqlClient.SqlConnection]::ClearAllPools()
Well, I know that this is a very old post and the people from Microsoft told that fixed this issue (as told the article mentioned by David Brabant) but maybe I'm not the luckiest guy and have to make an workaround to make it happens.
Even running Microsoft SQL Server 2012 (SP1) - 11.0.3128.0 (X64) I had the same issue and after make some researches I got a way to get some parameter from Invoke-Sqlcmd as output so I can get the Session ID of the current user process with the built-in ##SPID global variable from the SQL Server and make a connection with ADO.NET to execute a KILL clause to close the opened connection.
So let's to the workaround applied in my case
#Invoke the Invoke-Sqlcmd to execute an script from a file
Invoke-Sqlcmd -Server "[SERVER_NAME]" -Database [DATABASE_NAME] -Username [USER] -Password [PASSWORD] -InputFile [DOT_SQL_FILE_PATH]
#Invoke the Invoke-Sqlcmd to execute a inline SQL statement to get the SessionID as a Powershell variable
$SQLSession = Invoke-Sqlcmd -Server "[SERVER_NAME]" -Database [DATABASE_NAME] -Username [USER] -Password [PASSWORD] -query "select ##spid as SessionID"
# Build query to execute KILL clause
$DbQuery = "KILL " + $SQLSession.SessionID;
# Create SQL connection with ADO.NET
$DbConnection = New-Object System.Data.SqlClient.SqlConnection
$DbConnectionString = "Server = [SERVER_NAME]; Database = [DATABASE_NAME]; User ID=[USER]; Password=[PASSWORD];"
$DbConnection.ConnectionString = $DbConnectionString
$DbConnection.Open()
# Create SQL command for KILL clause
$DbCommand = New-Object System.Data.SQLClient.SQLCommand
$DbCommand.Connection = $DbConnection
$DbCommand.CommandText = $DbQuery
# Execute KILL clause
$DbCommand.ExecuteNonQuery()
# Close connection
$DbConnection.Close()
I hope that it helps
Even though I am using the newest version of SSMS (Version 16.5.3 - Build 13.0.16106.4), I still get this issue. I haven't figured out what the "right" way of forcing the connection closed is, but I have a work-around that is simple and resolves the issue for me. If you just need to get the connection off the database, you can do the following:
Run normal command(s)
Invoke-Sqlcmd -ServerInstance "SOME_SERVER" -Database "SOME_DB" ...
When you are ready to eliminate the connection from the database:
Invoke-Sqlcmd -ServerInstance "SOME_SERVER" -Database "SOME_DB" -Query "use [master];"
This will switch the connection to master, thus removing it from the database of interest. If you absolutely need the connection closed, I think you need to resort to SqlClient or such.