从C#.net进行差异备份和还原 [英] Differential Backup and Restore from C#.net
本文介绍了从C#.net进行差异备份和还原的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个具有相同表结构的数据库.一个数据库是实时数据库,它非常庞大.因此,我想删除7天以前的数据,但在此之前,我想进行差异备份并将其还原到其他数据库并保留最后一个数据.
I have two databases with same table structures. One database is live database and it is very huge. So that I want to delete 7 days older data but before that I want to take a differential backup and restore it to other database and retain the last data.
推荐答案
SQL Job将是实现这些方案的好选择.现在,要跟踪7天前的日期,可能有很多方法.我正在写一些我在某些应用程序中看到过的东西.您可以在创建日期"/更新日期"中创建一列,然后在创建/修改时只需更新此列即可.
SQL Job will be good choice to implement these scenarios. Now To track the 7 days older date there may be many approaches. One i am writing which i''ve seen in some applications. you can have a column with ''Created Date''/''Updated Date'' and on creating/modifying just update this column.
正如Peeyush Pachaori所建议的那样,我也将使用Sql代理程序完成此任务的工作.
为了从表中删除记录,您必须跟踪每条记录的插入/更新,级联删除也很方便.
删除代码:
As Peeyush Pachaori has suggested I would too use Sql Agent''s Job for this task.
In order to delete records from tables you must keep track of insertion/update for every record, cascade deletion could be handy as well.
deletion code:
DELETE FROM MyTable
WHERE LastUpdateTime < @requiredDate
差异备份代码:
code for diff backup:
BACKUP DATABASE [DBName] TO DISK = N'Backup_Path'
WITH DIFFERENTIAL , NOFORMAT, NOINIT,
NAME = N'DBName-Differential Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10
GO
希望对您有所帮助.
I hope this helps.
这篇关于从C#.net进行差异备份和还原的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文