T-SQL Backup Database command for file path with spaces? - tsql

How do I write a T-SQL backup database command to specify a file containing spaces?
Here is what I have:
BACKUP DATABASE AMDMetrics TO DISK = 'C:\Documents and Settings\daultrd\My Documents\DatabaseBackups\AMD_METRICS.DAT'
And this is the error I get:
Msg 3201, Level 16, State 1, Line 1
Cannot open backup device 'C:\Documents and Settings\daultrd\My Documents\DatabaseBackups\AMD_METRICS.DAT'. Operating system error 3(The system cannot find the path specified.).
Msg 3013, Level 16, State 1, Line 1
BACKUP DATABASE is terminating abnormally.

Try sharing your intended destination folder and using a UNC path to backup from the server to your local machine.
BACKUP DATABASE AMDMetrics
TO DISK = '\\YourMachineName\SharedFolderName\AMD_METRICS.DAT'

This works for me, are you sure that the directory is correct?
backup database master to disk = 'c:\Test Me\master.bak'
Processed 41728 pages for database 'master', file 'master' on file 1.
Processed 5 pages for database 'master', file 'mastlog' on file 1.
BACKUP DATABASE successfully processed 41733 pages
in 22.911 seconds (14.230 MB/sec).
copy and paste this into explorer and see if you can get there C:\Documents and Settings\daultrd\My Documents\DatabaseBackups
This of course has to be the same machine, otherwise you need to map a drive to the location or use UNC paths

I was working through this issue as well.
It's possibly that the Service that SQL Server is running under (Network Service by Default) doesn't have permission to the folder specified.
BACKUP DATABASE master TO DISK = 'master1.bak' WITH INIT
The above should backup to the default backup folder
if that works with no problem it'll be the problem stated.

Related

PostgreSQL Point-In-Time Recovery Getting Error with No valid checkpoint record

I am trying to perform a Point-In-Time Recovery using the WAL_ARCHIVE process. The archive command is added to the postgresql.conf file and I can see the WAL being archived in the backup-archive directory. When I try to start the service I get PANIC: could not locate a valid checkpoint record
I am using the below step-by-step process.
low level api basebackup
SELECT pg_start_backup('label', true, false);
copying the data directory of my cluster
tar -zcvpf basebkPostgres20230110New.tgz /PostgreSQL/13/data
closing my basebackup
SELECT * FROM pg_stop_backup(false, true);
Stopping the postgres service
Removing the current's cluster data directory
Restoring the backed up data directory
Removing the contents of the pg_wal directory
Setting the restore_command in the postgresql.conf file
Starting the postgres service
You forgot the backup_label file and recovery.signal. You have to capture the result of pg_stop_backup (or pg_backup_stop from v15 on) and create backup_label from the contents. That file has to be in the restored data directory. Also, you have to create recovery.signal in the data directory, so that PostgreSQL starts in archive recovery mode and reads your restore_command.
Without restore_command, PostgreSQL uses the WAL in pg_wal, which is empty. Without backup_label, PostgreSQL thinks that it can recover from the checkpoint indicated by the control file pg_control. Even if that worked, the result would be a corrupted database, since you have to recover from the start of the backup.
recovery.signal is documented here (step 7), and backup_label is documented here (step 4).

DB2 SQL3706N A disk full error was encountered

I have nearly 600+ files to load in DB2 database version 10.5.9. Each file size is nearly 200 MB. I have a batch script to upload each files in a loop.
My Disk "/mnt/blumeta0/db2/copy"size is 16 GB
If i run this upload with nonrecoverable mode it works. But i cant do that in my prod database.
I tried to db3 connect refresh and db3 terminate after each file uploaded but does not worked.
Manually cleaned up disk /mnt/blumeta0/db2/copy but total size of all files is more than 16 GB so got same error.
I cannot clean folder in script as clean up can be done with super user.
db2 "LOAD FROM $i OF DEL INSERT INTO <table_name>"
SQL3706N A disk full error was encountered on "/mnt/blumeta0/db2/copy".
How DB2 server cleans copy folder? Is there any other alternative i can try?
You suggested that the Load succeeds when using NONRECOVERABLE mode, however fails otherwise with error "SQL3706N A disk full error was encountered on "/mnt/blumeta0/db2/copy".
I'm guessing that the Load is being performed using the COPY YES option. Since the Load command that you pasted does not show the COPY YES option, I'm guessing that you have a special configuration setting enabled that forces Load operations to use COPY YES in order to prevent the table from becoming inaccessible in a rollforward recovery event or HADR standby takeover event. The name of this configuration setting (registry variable) is "DB2_LOAD_COPY_NO_OVERRIDE".
When the Load is performed with COPY YES, a copy of the table pages/extents that were generated during the Load operation is written into a copy image file.
I suspect that you have the registry variable "DB2_LOAD_COPY_NO_OVERRIDE=COPY YES /mnt/blumeta0/db2/copy" configured (you can use db2set -all on the database server to display all configured registry variables). If so, the copy image files are being stored in this path, which at 16GB appears to be too small to contain them all.
You can consider changing the location of this path to somewhere with more disk space, however the path should always be accessible in the event of a database rollforward recovery or hadr standby takeover, otherwise the table will not be accessible after such an event.

DB2: not able to restore from backup

I am using command
db2 restore db S18 from /users/intadm/s18backup/ taken at 20110913113341 on /users/db2inst1/ dbpath on /users/db2inst1/ redirect without rolling forward
to restore database from backup file located in /users/intadm/s18backup/ .
Command execution gives such output:
SQL1277W A redirected restore operation is being performed. Table space
configuration can now be viewed and table spaces that do not use automatic
storage can have their containers reconfigured.
DB20000I The RESTORE DATABASE command completed successfully.
When I'm trying to connect to restored DB (by executing 'db2 connect to S18'), I'm getting this message:
SQL0752N Connecting to a database is not permitted within a logical unit of
work when the CONNECT type 1 setting is in use. SQLSTATE=0A001
When I'm trying to connect to db with db viewer like SQuireL, the error is like:
DB2 SQL Error: SQLCODE=-1119, SQLSTATE=57019, SQLERRMC=S18, DRIVER=3.57.82
which means that 'error occurred during a restore function or a restore is still in progress' (from IBM DB2 manuals)
How can I resolve this and connect to restored database?
UPD: I've executed db2ckbkp on backup file and it did not identified any issues with backup file itself.
without rolling forward can only be used when restoring from an offline backup. Was your backup taken offline? If not, you'll need to use roll forward.
When you do a redirected restore, you are telling DB2 that you want to change the locations of the data files in the database you are restoring.
The first step you show above will execute very quickly.
Normally, after you execute this statement, you would have one or more SET TABLESPACE CONTAINERS to set the new locations of each data file. It's not mandatory to issue these statements, but there's no point in specifying the redirect option in your RESTORE DATABASE command if you're not changing anything.
Then, you would issue the RESTORE DATABASE S18 COMPLETE command, which would actually read the data from the backup image, writing it to the data files.
If you did not execute the RESTORE DATABASE S18 COMPLETE, then your restore process is incomplete and it makes sense that you can't connect to the database.
What I did and what has worked:
Executed:
db2 restore db S18 from /users/intadm/s18backup/ taken at 20110913113341 on /<path with sufficient disk space> dbpath on /<path with sufficient disk space>
I got some warnings before, that some table spaces are not moved. When I specified dbpath to partition with sufficient disk space - warning has disappeared.
After that, as I have an online backup, I issued:
db2 rollforward db S18 to end of logs and complete
That's it! Now I'm able to connect.

Why can't i backup database using t-sql?

I try to backup database using code below :
backup database RestaurantManagement to disk = 'd:\'
sqlserver always show the message below :
Msg 3201, Level 16, State 1, Line 3
Cannot open backup device 'd:\'. Operating system error 3(The system cannot find the path specified.).
Msg 3013, Level 16, State 1, Line 3
BACKUP DATABASE is terminating abnormally.
How can i code it ? help...
You need to provide the backup file name, like this:
backup database RestaurantManagement to disk = 'd:\backups\RestaurantManagement.bak'
Are you a member of the appropriate sql role? Does the account which Sql Server is running under have permissions to the path? Are you sure the media is available on the server? What I mean is, you may have a d: on your machine, but the paths you give are for the remote server.
The error you're getting indicates there's no d: drive, or no folder named backups.
I would double check all those things.

log location in db2

Where are log file stored in DB2?
I am searching for a file with name Updatedb20100604182008.log
from this page:
http://www.ibm.com/developerworks/data/library/techarticle/0301kline/0301kline.html
(The article goes into further detail about default locations as well.)
The database logs are initially
created in a directory called
SQLOGDIR, a sub-directory of the
database directory. You can change the
location where active logs and future
archive logs are placed by changing
the value for this configuration
parameter to point to either a
different directory, or to a device.
Archive logs that are currently stored
in the database log path directory are
not moved to the new location if the
database is configured for
roll-forward recovery.
Because you can change the log path
location, the logs needed for
roll-forward recovery may exist in
different directories or on different
devices. You can change this
configuration parameter during the
roll-forward process to allow you to
access logs in multiple locations.
The change to the value of newlogpath
will not be applied until the database
is in a consistent state. An
informational database configuration
parameter, database_consistent,
indicates the status of the database.
Note: The database manager writes to
transaction logs one at a time. The
total size of transactions that can be
active is limited by the database
configuration parameters:
The DB2 log file location can be found from the DB CFG parameter - 'Path to log files'.
The command would be the below, without an explicit connection to the DB.
db2 get db cfg for db_name | grep 'Path to log files'
Else, you can connect to the DB first and use the command as follows:-
db2 connect to db_name
db2 get db cfg | grep 'Path to log files'
db2 terminate
db2 connect to database
db2 get db cfg | grep -i log
cd /data/dblogs/NODE0000(path to the log files)
cd LOGSTREAM0000(these is log folder)
ls -altr(we can see all the log files with .log extension)
rm abc.log (give the log name which you want to delete)