H2 Database : how unlock a database file for backup copy? - backup

I'm using h2database version 1.4.200 with hibernate for saving in database file.
My programs needs to regulary save backup and I don't care about corruption's file's problems.
After looking the documentation : http://h2database.com/html/features.html#database_file_locking
I decided to use parameter LOCK_FILE=NO. I saved my models and keeped the entity manager opened. When I tryed to copy the db file "data.mv.db", my database file was always locked even if I used Lock_FILE=NO.
Parameter LOCK_FILE=NO, does it work correctly ?
There is a alternative for copying speedly my db-file in java ?

Any attempt to copy the file when database is in use is a way to get a possibly corrupted backup.
H2 has BACKUP command for online backups.
BACKUP TO 'filename.zip'
This command creates a ZIP archive with a consistent copy of the database file.

Related

Make PostgreSQL DB copy with qt tools

Is it possible to make a copy of database using qt? For example I’m connected to some db and want to save a copy of this db as copy.sql file in a some folder and then maybe save it on cd or somewhere else.
The only good way to make an SQL export of a PostgreSQL database is to use pg_dump. So you should call that executable from your application.
Be warned though that such a dump is only guaranteed to work when restored to a database of the same major version.

how can I get the data out of an .fb file?

I'm working with a company trying to setup a new database system as their old database software has gone out of business. All the data is in a .fb file that is encrypted (You used to have to get backups 'unlocked' before they would let you use them).
I've managed to get a copy of the database (I think it's unencrypted as I copied it while the database was open and then changed the copied files permissions using terminal).
The problem is that it's a .fb file and I can't find a way to 'open' it to browse the data...
Any Ideas?
Generally speaking, data stored in relational databases aren't just stored as ascii csv files. So you won't be able to just open up a .fb file in a text editor and grab the data.
If you're still able to query the database, you will need to have the frontbase server generate a dump of the data into a flat file.
See the frontbase documentation for backup and restore. Specifically 4.9.1. Exporting Schema and Content Data:
WRITE ALL OUTPUT('<output-directory>' [,'YES']);

Backup failed for Server, The media is formatted to support 2 media families Error

Can any body tel me how to overcome this error when taking a backup in SQL Server 2008 Express?
Backup failed for Server '\SQLEXPRESS'. (Microsoft.SqlServer.SmoExtended)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=10.50.1447.4+((KJ_RTM).100213-0103+)&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Backup+Server&LinkId=20476
System.Data.SqlClient.SqlError: The media loaded on "D:\Project 2014\PayrollBackup" is formatted to support 2 media families, but 1 media families are expected according to the backup device specification. (Microsoft.SqlServer.Smo)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=10.50.1447.4+((KJ_RTM).100213-0103+)&LinkId=20476
I just want to take a single backup of my database. But always I have to give two destinations and then when restoring I cant restore the database using a single backup file? Is there anything to configure in SSMS? If any, could you please clearly explain?
EDIT:
BACKUP DATABASE [Payroll] TO DISK = N'D:\Project 2014\PayrollBackup' WITH NOFORMAT, NOINIT, NAME = N'Payroll-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10
GO
A simple solution has arisen (via SSMS), based on the answer of #DMason and answer of #Carol Baker West.
Just create a new media set for a single media family.
The backup statement is using the NOINIT clause. This causes each successive backup to append to the existing backup file. You are attempting to backup to one media set (one file), but it appears the existing backup you are attempting to append to consisted of two media sets (two files).
For a quick turnaround, specify a new filename:
BACKUP DATABASE [Payroll] TO DISK = N'D:\Project 2014\<insert new filename>' WITH ...
The issue for me was there were two sources in the Destination.
After you backup with only one destination, removing the other. You don't get the error anymore.
Let me know if this helps!
I also received the error. In my case, I wanted to specify a different location to which the file should be backed up to. But what it was trying to do, was to now split the backup to both files in both locations - thus the part of the error:
is formatted to support 1 media families, but 2 media families are expected according to the backup device specification. (Microsoft.SqlServer.Smo)
So, remove one of the destinations specified in the 'Destination' section of the Back Up Database wizard. It should only have one destination if it only backed up to one file previously.
I got the same error with my project, so I did a couple of simple things:
Copied my old MyDB.bak file from the default backup path, say C:\Program Files\Microsoft SQL Server\MSSQL14.SQLEXPRESS\MSSQL\Backup
Removed it from there
Backed up new version of DB to the same path. (It now succeeded)
Copied the newly created backup to desired place.
When I was attempting to restore a backup onto another server, I got the same error that you got.
I was able to get past this error by deleting the "Backup Device" object and recreating a new one. As you know, the Backup Device is an object that saves a path to your backup folder and to the backup file. Apparently, it also saves other information like the media family.
In the SSMS interface, expand the Server Objects section, and then the Backup Devices section. Find the named backup device for the database and path that you are getting the error on. Delete that object and recreate it. That should take care of the issue.
Now, just so we are clear, I'm NOT talking about deleting the backup itself. I'm NOT talking about deleting or removing any drives. I'm NOT talking about deleting all of the backup devices listed on your server. I'm simply talking about deleting the backup device (which is an object) for one database on your server.
I received this message when I was adding a database to Always On Group and log backup failed with this message:
'The Backup cannot be performed because the existing media set is formatted with an incompatible version'
Problem: I was using the same backup shared folder as I was using two servers with multiple instances. Database was promoted from SQL Server 2008 R2 to SQL Server 2016. I did not delete the old 2008 R2 backups from that shared folder.
Solution: Try and clear out the old version backups and try again. It worked for me.

Restoring a database from .bak file on another machine

I've not done much SQL and am still pretty new to this, so please excuse what's probably a basic question.
I've been asked to look into creating an SQL job to backup our databases, store the .baks on another machine and then to restore them to a second server. I've been doing a bit of research and playing with SSMS and have back-ed up the database to my personal machine by setting up a share and running a backup job to the share location. I'm now trying to create a new database (on the same server I back-ed up from) by restoring the .bak file (but giving the database I'm trying to create a new name and what-not) but am unable to specify restoring it from the share, like I did when backing it up/I can't find how to specify other network locations and am just browsing the server's C drive when I try to locate the file.
For now, I'm just using the built-in wizards to try and achieve this (open SSMS -> Connect to server -> right click DataBases -> Restore DataBases and then select From Device and browse to find the file).
This isn't the final process, just me trying to get to grips with how this works. As I said, the idea is to ultimately have a scheduled job to backup the DB from server1 to a .bak on, say, my personal machine and then to restore that to a DB on server2 (different network, different city) and, probably, with a series of SQL commands rather than using the wizard every time (there are a few DBs that'll, ultimately, need backing up).
My apologies for the, possibly, quite drawn out and convoluted question - essentially, all I need to know is can I/how can I restore a DB in SSMS from a .bak on a different machine?
Many thanks
You could use something like the following script. It restores a database from the filesystem, and it overwrites the existing database with the name of "MyDB", moving the files to new locations of your choice in the process.
RESTORE DATABASE
MyDB
FROM DISK = '\\MyShare\MyBackup.bak'
WITH
MOVE 'DataFile' TO 'D:\myNewDBLocation\DataFile.mdf',
MOVE 'LogFile' TO 'E:\\myNewDBLocation\LogFile.ldf'
, REPLACE
You can find out the name of the llogical files (in the above, those are called DataFile and LogFile by running the following:
RESTORE FILELISTONLY
FROM DISK = '\\MyShare\MyBackup.bak'
Additional information about various options and parameters:
RESTORE (Transact-SQL)

SQL Server MDF file

I am working on a website that has access data from a database (sql server). It will also be adding, updating deleting records in the database. It seems like there is an MDF file that gets created containing the database schema and all the records I guess? Once development is complete and I want to move this database to a real server then all I need to do is move this MDF file to the real server and that is it? is it that simple? or not really?
Also, I hope the MDF file is not a read-only file and can be updated/modified or is it?
Yes, the MDF data file (and the associated *.LDF transaction log file) contains all the database objects that make up your system.
And yes, you can definitely detach a database (an .MDF/.LDF file pair) from your (dev) SQL Server, copy it onto another "real" Production SQL Server, and re-attach it there, without loss of data or information.
Yes, the MDF file is modifyable - through the SQL Server commands and methods. You should never tamper with the file yourself, directly (flipping bits). Use SQL Server and its official interfaces (T-SQL, ADO.NET etc.) to work with your data.
Yes you can do that. Right click the database and click "detach". Make sure you click the drop connections box and click ok (if you don't do this some errors could occur). You can now move the mdf and ldf files.
However, there is a better way imho. Instead, create a full backup of the database, copy the backup file, and restore from the backup on the new server. Now you have two copies of the database, a development version and a production version.
You will need to take .MDF file as well as .LDF file which will have your logs. You have to take both mdf and ldf files and attach on the real server.