DB Engine :: Take Only Last 1 Year Data Backup Using Script From Server
May 20, 2015I have last 5 years data in my database(SQL server).
I want to take backup only last 1 year(last 365 days) data using SQL script.
I have last 5 years data in my database(SQL server).
I want to take backup only last 1 year(last 365 days) data using SQL script.
Our business get orders through the week with the weekends (Fri & Sat) orders being higher than weekdays. Im wanting to graph this years data with last years and possible the years before but to compare days in such a way that the all the weekdays line up. so comparing 2015 week 1 with 2014 week 1 but with 03/01/2015 (Sat) lining up with 04/01/2014 (Sat) etc.
I'm looking for alternatives to adding or removing days from the dates to solve this issue, i have a date dimension table for the past 5 years that i can use to compare calendar week 201401 with calendar week 201501 but I am finding it a bit inflexable.
I am restoring a backup of sql server 2005 which I inherited on to sql server 2012 and is in a recovery pending state and the reason why is, this is a backup from a different domain and does not have the logins from the legacy domain, looks like its some access issue as its not being able to find the necessary login on sql server 2012.
View 4 Replies View RelatedI have a VM with Windows Server 2012 and SQL 2014 installed. Some things about the VM: Using VMware Workstation 11. Created with 160 GB hard disk and 4G memory (that's all we could do when needing to run multiple VMs from the box we're using). I am able to get to the internet and to our network but the internet connection tells me that there is no internet access and we can't seem to fix it.When I attempt to create a backup of one of my DBs, I receive the attached error. No other backup has been created for this particular DB so it would not need to overwrite anything. This is an issue for all of the DBs that are in the SQL Server and not just an isolated DB.
We ran DBCC CHECKDB against the DB and no errors were returned.A bit about the DBs: Our software creates a number of empty DBs upon install. For testing purposes we have DBs that are populated with data that we restore once the install is complete. So our procedure is, once all services are shut down for our software and the SQL connection has been cut, we delete the DBs created during install and restore the DBs that will replace them. All of the DBs restored successfully so I don't understand why there would be an issue with backing them up.
I am working on a project for an SQL job. I am:
1.) Taking a database out of an availability group,
2.) Setting the recovery to simple,
3.) Shrinking the log file,
4.) Setting the recovery mode back to full,
5.) Then backing it up.
I need to restore the file to my secondary server with replace and non recovery mode. I am having trouble performing that call? I have the code to reestablish the database to the availability group if I can get the restore feature working.
I am trying to make my maintenance plan to backup on a remote server but it fails with:
"failed with the following error: "xp_delete_file() returned error 2".
I am pretty sure its because it doesnt have full access to the share folder... My question is, how can I grant access to it, if I am using a local account as sql agent service: NT ServiceSQLSERVERAGENT.I need to change the service account?
How to move the database backup files (.bak) from one server to another server using ‘XP_CMDSHELL’
View 2 Replies View RelatedI got full backup on daily schedule its taking more space on Drive because each file has more than 25GB.I am using SLQ server 2008R2 so I'm looking to take the backup with compression instead of uncompressed Backup. What are the impacts of compressed backup. Is there any problems with compressed backup while restoring the backup file.
View 8 Replies View RelatedI have two queries that give me the total sales amount for the current year, and the last year.
SELECT SUM([Sales (LCY)])
FROM [$Cust_ Ledger Entry] cle
LEFT OUTER JOIN dw.dim.FiscalDate fd
ON fd.CalendarDate = cle.[Posting Date]
WHERE [Customer No_] = '10135'
AND fd.CalendarYear = '2013'
[Code] ....
I would like to learn how to be able to make this a single query and end up with two columns and their summed up totals. Like it shows on the attached image.
This is my query without the columns I need:
SELECT
c.CustomerNumber
,c.Name
,c.ChainName
,c.PaymentTermsCode
,cle.CreditLimit AS 'CreditLimit'
,SUM(cle.Amount) AS 'Amount'
[Code] ....
I need to build a report that compares a count on a certain day of the week by month by year by stacks. That is,for first Monday in October 2012 against first Monday in October 2013 for stack DM1 against first Monday in October 2014 stack DM1, same for second Monday, first Tuesday, second Tuesday, ect. Attached is a sample dataset and what I want to achieve.
View 9 Replies View RelatedServer consolidation is the word of the day here. One of the elements is to use, when applicable, virtual machines in our devstageprod environment. Our sql servers (with local storage) are well utilized and run fine. I don't want to move the entire server (sql 2005 engine + data) into a VM as I think performance will be bad. But, per my question, if only the sql engine is running in a VM while the data is stored on our SAN, I think we may achieve acceptable performance.
Do you have any thought or experience with this mix of Vm and SAN from a sql perspective?
TIA,
Barkingdog
I have 5 TB of data in production and my development team requested to restore only last month data(<=500 MB ) in staging server and last 2 months data in pre production.
View 3 Replies View Relatedwhat is the best practices to store Landset Data in SQL Server? volume of data should grow up to 100 TB
View 3 Replies View Related I have three instances running on my sql 2008 r2 enterprise.I have taken full backup of one database from default instance.I login both the instances thru sa account.Now when I try to restore that backup on another instance it gives me the following error....
TITLE: Microsoft SQL Server Management Studio
Restore failed for Server 'WRCP2F1CWS315TEJA'. (Microsoft.SqlServer.SmoExtended)
System.Data.SqlClient.SqlError: The operating system returned the error '32(The process cannot access the file because it is being used by another process.)' while attempting 'RestoreContainer::ValidateTargetForCreation' on 'C:Program FilesMicrosoft SQL
ServerMSSQL10.MSSQLSERVERMSSQLDATAfcms.mdf'. (Microsoft.SqlServer.Smo)
what can be done to restore bakup in another instance ...
In one off my production box, we are notable to take a backups of MSDB . When i look at the error, it is failing locate allocation unit ID.. complete error as below
Msg 2533,Sev 16,State 1, Line 36 : Table error : Page (1:111720 ) allocated to object id 110623437, index ID 1, Partition ID 72057594043432960, alloc unit ID 72057594044874752 (type-inrow data) was not seen. This page is invalid or may have an incorrect alloc unit ID in its header.[SQLSTATE 42000]
Due this failure, we are unable to take the backup of MSDB database and our integrity check and reindex jobs also failured with the same.Also, I could see events of I/O issues with underlaying hard dirve with following name
DeviceHarddisk0DR0,has a bad block.
1. I dont no what could happen if restart my server, Question is: Does it recognize MSDB during server statup.
way to read data from database already stored as question marks .that because by mistake i insert the data "arabic" from the VS as sqltext but the field in the database is nvarchar now i want to get the data back.
View 4 Replies View RelatedI am trying to take backup on network folder but I am getting below error:
Msg 3201, Level 16, State 1, Line 9
Cannot open backup device 'xyz.xy.z.xyabcdexyxyzarchive_2015_7_14_11_14_58.Diff'. Operating system error 1326(Logon failure: unknown user name or bad password.).
Msg 3013, Level 16, State 1, Line 9
BACKUP DATABASE is terminating abnormally.
NOTE:- The folder abcde is protected by password , When I try to open the xyz.xy.z.xy, I provide password to connect.
I am using the below script :
DECLARE @filename VARCHAR(255)
SELECT @filename ='xyz.xy.z.xyabcdexyxyzarchive_' +
LTRIM(STR(DATEPART(year, GETDATE()))) + '_' +
LTRIM(STR(DATEPART(month, GETDATE()))) + '_' +
[Code] ...
How to troubleshoot / resolve this error permanently?
I am using alwayson on my SQL 2012 databases. I am using ola hallengren scripts for backing up databases. Full & diff db backups work fine, but the log is not getting backed up. The tran log backup job doesn't error out too. Trying to figure out what I may be missing?
View 10 Replies View RelatedIs it possible to backup/restore sql server databases in a logical way like oracle(exp/imp, expdp,impdp, can export/import tables/users etc)?my case, I have a database which has many data files, in different file groups, I would like to put them together into one file and don't want to shred the database.
View 6 Replies View RelatedWe have a user with read,write and execute permissions.
But this user with is used by a windows application,Is able to backup on the Database server(On C: drive).
How can I prevent it to backup on the server.
I keep getting below stack dump errors whenever I try to take Full/T-Log backup.
2015-11-26 05:18:03.44 spid79 * Exception Code = c0000005 EXCEPTION_ACCESS_VIOLATION
2015-11-26 05:18:03.44 spid79 * Access Violation occurred reading address 00007FFFA6CF9C60
I used debugger and got below stack trace.
0:048> kC 1000
Call Site
sqlmin!GetObjOffsets
sqlmin!PerfmonManager::AddInstance
sqlmin!BackupPerfmonCounter::AddInstance
[Code] ....
How can I take backup of Database Audit Specification ?
View 3 Replies View RelatedI have a full backup scheduled at 12.00AM ET and have a batch import on 11.55PM(5 min before full backup) which takes 30min to complete .Will the backup cover the data which is being imported?
View 2 Replies View RelatedI used sql server 2012 express Import and Export Data (32-bit) wizard to import data from excel 2010 to a given table. But I got the following error message: Error 0xc0202009: Data Flow Task 1: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80004005.An OLE DB record is available. Source: "Microsoft SQL Server Native Client 11.0" Hresult: 0x80004005 Description: "Unspecified error". (SQL Server Import and Export Wizard)
Error 0xc020901c: Data Flow Task 1: There was an error with Destination - MPRecord.Inputs[Destination Input].Columns[Top1] on Destination - MPRecord.Inputs[Destination Input]. The column status returned was: "The value violated the integrity constraints
for the column.". (SQL Server Import and Export Wizard)
Error 0xc0209029: Data Flow Task 1: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The "Destination - MPRecord.Inputs[Destination Input]" failed because error code 0xC020907D occurred, and the error row disposition on "Destination - MPRecord.Inputs[Destination Input]" specifies failure on error. An error occurred on the specified object of the specified component. There may be error messages posted before this with more information about the failure. (SQL Server Import and Export Wizard)
Error 0xc0047022: Data Flow Task 1: SSIS Error Code DTS_E_PROCESSINPUTFAILED. The ProcessInput method on component "Destination - MPRecord" (35) failed with error code 0xC0209029 while processing input "Destination Input" (48). The identified component returned an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running. There may be error messages posted before this with more information about the failure.
vendor did a full backup for his database and put some folder not being backed up by TSM, he is the owner of the database, and delete his backup later. The backup is not copy only, all the differential and log backups taken are based on his FULL backup. so they cannot be restored.
QUESTION: To prevent this happen in the future, what is the normal practices? or any way to prevent db_owner to do the ad-hoc full backup? I am thinking of using DENY backup database, or write a policy claiming no responsibility if vendor make it happen again.
Current am using the below script it is working fine i need use ENCRYPTION script where i should add this
NOREWIND, NOUNLOAD, COMPRESSION,
ENCRYPTION(ALGORITHM = AES_256,
SERVER CERTIFICATE = [BackupCertificate]), STATS = 10
USE [master]
GO
[code]...
Backing up all databases on a sql server that hosts secondary high availability databases as well as other databases. The other databases back up fine, but the high availability secondaries all get the same error:
BackupDiskFile::OpenMedia: Backup device 'F:MSSQLBackupdbnamedbname_backup_2015_MM_DD_tttttt_ttttttt.bak' failed to open. Operating system error 2(The system cannot find the file specified.)
I have a database size of 9.8TB and I backup it to 30 backup devices. Each one has 110GB after backup compression.I tried to restore these files to standby server via 100MbE network but it always failed. My colleague told me this never happen before and I said yes because I have done this before a lot of times when backup devices are significantly smaller.He said the only way is to copy backup files locally and restore locally. But I am trying another method, I create more: 64(maximum) backup devices and try to restore via network again.SQL server version is Microsoft SQL Server 2012 (SP1)
- 11.0.3401.0 (X64) Jan 9 2014 13:22:15 Copyright (c) Microsoft Corporation
Enterprise Edition: Core-based Licensing (64-bit) on Windows NT 6.1 <X64> (Build 7601:
Service Pack 1) .
--- error message ---
5 percent processed.
10 percent processed.
15 percent processed.
[code]....
RESTORE DATABASE is terminating abnormally.
When I execute the following transaction log backup TSQL in SSMS
BACKUP LOG ProductDB
TO DISK = 'D:Database_BackupTransProductDB.trn';
I get this error:
Msg 3201, Level 16, State 1, Line 2
Cannot open backup device 'D:Database_BackupTransProductDB.trn'. Operating system error 21(The device is not ready.).
Msg 3013, Level 16, State 1, Line 2
BACKUP LOG is terminating abnormally.
I also have a daily database backup job that puts the backup file under this directory.
D:Database_BackupData
So I changed the path to this and it still fails.
BACKUP LOG ProductDB
TO DISK = 'D:Database_BackupDataProductDB.trn';
However if I change it to this path, it works:
BACKUP LOG ProductDB
TO DISK = 'MyServerDataProductDB.trn';
This turns out to be the path I used a few weeks back when I backed up the log for the very first time. But I now wanted to store my transaction log backups in D:Database_BackupTrans.
Is it possible to force row level locking in Sql server 2015 before inserting the data and release the same afterwords..find the code for which we would like to impliment the same
DECLARE @TravelAgentid Varchar(20)
DECLARE @Date DATETIME2(7)
DECLARE @InsDate DATETIME2(7)
set @TravelAgentid ='A101'
[code]....
I am trying to set up log shipping in a clustered server environment. I am pretty confused about the location of the shared folder to be created to put backup created by log shipping job. Which drive should I use either local or clustered shared drive to store the backups in primary server and to copy the same in secondary Server?
View 2 Replies View RelatedI have the following script that calculates Sales by month and current year.
We run a Fiscal year from April 1st thru March 31st.
So April 2012 sales are considered Fiscal Year 2013.
Is there a way I can alter this script to get Fiscal Year Totals?
select ClassificationId, YEAR(inv_dt) as Year, cus_no,
isnull(sum(case when month(inv_dt) = 4 then salesamt end),0) as 'Apr',
isnull(sum(case when month(inv_dt) = 5 then salesamt end),0) as 'May',
isnull(sum(case when month(inv_dt) = 6 then salesamt end),0) as 'Jun',
isnull(sum(case when month(inv_dt) = 7 then salesamt end),0) as 'Jul',
[Code] ....
Data returned looks like the following.
ClassificationID Year Cus_no Apr May June ....
100 2012 100 $23 $30 $400
100 2013 100 $40 $45 $600
What I would need is anything greater than or equal to April to show in the next years row.
I'm trying to generate a report using matrix like this
Month
Product PreviousYearSalesAmount SelectedYearSalesAmount %SalesDifference
I can populate year sales amount, but i cant calculate the percentage.
Note: Month and Year are passed as parameters.