Create Sql Server Backup on Local Machine - sql-server-2008

I am using SQL Server Management Studio running on my local machine.
I can log on to a remote box (database engine) and use the
Studio to create a database backup which is saved to a drive on the remote box.
How do I get it to save the backup to a drive on my local machine?

See this MSDN article, for the section on backing up to a network share, e.g.:
BACKUP DATABASE YourDatabase
TO DISK = '\\SomeMachine\Backups\YourDatabase.Bak';
Backing Up to a File on a Network
Share For SQL Server to access a
remote disk file, the SQL Server
service account must have access to
the network share. This includes
having the permissions needed for
backup operations to write to the
network share and for restore
operations to read from it. The
availability of network drives and
permissions depends on the context is
which SQL Server service is running:
To back up to a network drive when SQL
Server is running in a domain user
account, the shared drive must be
mapped as a network drive in the
session where SQL Server is running.
If you start Sqlservr.exe from command
line, SQL Server sees any network
drives you have mapped in your login
session.
When you run Sqlservr.exe as
a service, SQL Server runs in a
separate session that has no relation
to your login session. The session in
which a service runs can have its own
mapped drives, although it usually
does not.
You can connect with the
network service account by using the
computer account instead of a domain
user. To enable backups from specific
computers to a shared drive, grant
access to the computer accounts. As
long as the Sqlservr.exe process that
is writing the backup has access, it
is irrelevant whether the user sending
the BACKUP command has access.

STEP 1 : From sql-server 2008 connect to remote server
STEP 2 : Right Click server database
STEP 3 : Select Export Option
STEP 4 : Follow Instructions, Import to local server database and Backup from Local database

In Microsoft SQL Server Management Studio you can right-click on the database you wish to backup and click Tasks -> Generate Scripts.
This pops open a wizard where you can set the following in order to perform a decent backup of your database, even on a remote server:
Select the database you wish to backup and hit next,
In the options it presents to you:
In 2010: under the Table/View Options, change 'Script Data' and 'Script Indexes' to True and hit next,
In 2012: under 'General', change 'Types of data to script' from 'Schema only' to 'Schema and data'
In 2014: the option to script the data is now "hidden" in step "Set Scripting Options", you have to click the "Advanced" and set "Types of data to script" to "Schema and data" value
In the next four windows, hit 'select all' and then next,
Choose to script to a new query window
Once it's done its thing, you'll have a backup script ready in front of you. Create a new local (or remote) database, and change the first 'USE' statement in the script to use your new database. Save the script in a safe place, and go ahead and run it against your new empty database. This should create you a (nearly) duplicate local database you can then backup as you like.
If you have full access to the remote database, you can choose to check 'script all objects' in the wizard's first window and then change the 'Script Database' option to True on the next window. Watch out though, you'll need to perform a full search & replace of the database name in the script to a new database which in this case you won't have to create before running the script. This should create a more accurate duplicate but is sometimes not available due to permissions restrictions.

You can't - the remote machine has no information about your local machine's setup and cannot see the drives on it. You'd have to setup a shared folder on your local machine, and make sure the remote machine has access to it (which will mean both the SQL Server Agent and SQL Server services on the remote machine will need access to it via domain accounts).

If the remote machine is on the same network as your machine, see AdaTheDev's answer.
Otherwise you'll have to RDP or FTP into the remote machine and transfer the backup manually. I recommend 7-zip'ing it by the way.

Related

GCP MS SQL Server 2017 how to bulk load csvs from local machine

I have a Microsoft SQL Server 2017 database on Google Cloud. I'm trying to bulk load CSV files from my local machine to the database, using the following command
BULK INSERT umls.mrxw_spa
FROM 'C:\data\umls\2020AA\META\MRXW_SPA.RRF'
WITH (FIELDTERMINATOR = '|', BATCHSIZE = 10000);
but I get an error message
Cannot bulk load. The file "C:\data\umls\2020AA\META\MRXW_SPA.RRF" does not exist or you don't have file access rights.
I don't know how to give the GCP SQL Server permissions to my local folder. This database used to be on Azure and it was quite easy to load, but the company changed its licensed and moved to Google Cloud. I know I could create a python script to load the data - but using the above command is a lot easier.
Has anyone been able to use the Bulk Insert in the GCP?
You do not. The standard approach for bulk load is to move the data onto the server and load from there. IF you would have a proper network in place.... you would still have to use a UNC form (\machine\fileshare\path\file).
Basically your bulk insert command is sent to the server. THe server then looks for the file at c:\data.... (basically the path). This command is NOT EXECUTED ON YOUR COMPUTER. No SQL is. They all are sent to the server.
Giving the server permissions on your local machine is not an option. Besides that being tricky without domain - the server will likely NOT BE ABLE TO REACH YOUR MACHINE because it is behind NAT. So, your question is akin to "how can I bypass he secretary on (whatever ceo) office?" and then not even having the phone number of his office. Unless you have a network setup that allows the server to reach you (99.9% chance you do not have that in place) the permissions are useless to start with.

How protect MySQL database from dump and clone?

my question is whether the password-protected server and database can be protected from copying so that my malicious customers to bypass security settings.
MySQL server has:
user -> 'root' with password with disable global privilege
user -> 'javaAPP' with password with limited privilege only for working database and disable disable global privilege
user -> 'superadmin' with global privilege
When try comand mysqdump requires password and allows action only for user 'superadmin'.
When copy folder '\data' with exist working database folder and every files to other computer all user settings permissions and passwords are transferred to the new server. So it's look ok.
When copy only database folder '\data\javaAPPdatabase' to other computer ... i see the tables empty .. no fields. I guess this is due to missing user rules.
So ... more what I need to do to protect unauthorized access to the database ?
I am trying to protect my java application through the database
Please help me!?
MySQL server is located in client network on client PC.
I recognize my knowledge in mysql is reduced to working functions, triggers and procedures.
MySQL server is located in client network on client PC.
Then it's theirs. They have complete access to it. There's no way to prevent them from reading all the data anytime they want.
Even if you restrict access with passwords, they can restart the MySQL service with the skip-grant-tables option enabled, so passwords are not enforced (see https://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html).
The only way you can limit access to the data is NOT to install the database at the client site. Host the data yourself, and provide an API to access it through a web service you host.

Attach a remotely stored database

Is it possible to attach a database that is stored on a remote server because when I mapped a drive and tried to attach it in management studio, the drive does not show up as an option. I moved it because of disk space and if I cannot what is the alternative suggestions?
You should be able to attach a database on UNC path (I wouldn't use a mapped drive - that drive is mapped for you, not the SQL Server service account), but you have to ensure that the SQL Server service account has read/write permissions on the remote folder, and you have to run trace flag 1807 (please read Brent Ozar's post about this).
Also don't use the GUI for this. Once you have the trace flag set, have restarted the service, and have configured permissions correctly, use a new query window, and run the following command:
CREATE DATABASE db_name
ON (Filename = '\\uncpath\share\file.mdf'),
(Filename = '\\uncpath\share\file.ldf')
FOR ATTACH;
(The UI is never going to offer you a UNC path no matter what trace flags you have set or what permissions are enabled.)
Be prepared to handle a corrupted and possibly unrecoverable database should the network share go down, of course.
If that sounds scary to you, good! It should! This is not a good idea at all. Instead you should free up some space, add a drive, or host the database on a different instance.

Encrypting Mysql database stored files on disk

Is it possible for Mysql to encrypt its stored files (database scheme & data on disk) in a way that someone not be able to copy these files to another machine that and read them using his own installed Mysql root user?
if not is there a DBMS that be able to protect database stored files on disk by encryption?
Unfortunately, MySQL doesn't support data file encryption natively.
However, there are 3rd products out there like:
http://www.vormetric.com/products/vormetric_database_encryption_expert.html
To be honest, if the database content has any commercial value or contains personal data about individuals, you should really control who has access to the datafiles (whether encrypted or not).
To use the windows EFS encryption:
http://windows.microsoft.com/en-us/windows/encrypt-decrypt-folder-file#1TC=windows-7
Read more obout it:
http://www.petri.co.il/how_does_efs_work.htm#
!!! Don't forget to export the certificate !!!
If you are using windows EFS and starting MySQL as a service, you will need to do the following:
go to Services and find the MySQL service
stop the service
right-click -> properties -> LogON TAB
check "This account"
fill your windows account name eg. ".\username"
provide your password
start the service
The MySQL service should now start without errors.

I accidentally deleted all the logins in my SQL DB, now I am unable to connect

Is there anyway to get in the server and recreate them?
I actually found a much simpler solution to this here:
http://blogs.msdn.com/b/raulga/archive/2007/07/12/disaster-recovery-what-to-do-when-the-sa-account-password-is-lost-in-sql-server-2005.aspx
The short version (in case that link dies) is that if you restart the sql server in single user mode "net start mssqlserver /m" then a member of the local machine's administrator group will be able to connect with windows authentication. You can then change the sa password, add new accounts, or whatever you need.
You'll have to reinstall the server as there is no "grip" available to run anything to restore the accounts or create new ones.
Since you can't backup your databases either (again, no way to get there from here) you'll want to stop the SQL Server service (MSSQLSERVER) in the Services panel so that it releases its exclusive lock on your database files. Next, navigate to C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data and copy all of the MDF and LDF files to a safe spot.
Next, uninstall and re-install SQL Server (you may be able to just reinstall). Once you are up and running again, copy the MDF/LDF files back (NOT the model, msdb or master databases!! Just the ones that YOU have created) and "attach" them in a SQL window. You'll do all of this with the Windows integrated account.
Does the surface area configuration tool still work? If so you could attempt to use that to add another admin to the instance.