暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

sybase备份恢复

原创 七七 2022-06-22
854

 

1.使用dump命令前需要启动数据库服务和备份服务

startserver -f ./RUN_T66

startserver -f ./RUN_T66_BS

 

2.创建测试库

(1)创建数据库前需要创建数据设备和日志设备

disk init

name="dhrdata",

physname="/sybase/T66/dhr/data.dat",

size="1G"

go

 

disk init

name="dhrlog",

physname="/sybase/T66/dhr/log.dat",

size="1G"

go

 

(2)创建测试数据库

create database dhrdb

on dhrdata="1G"

log on dhrlog="1G"

Go

(3)在测试库中创建测试表并插入数据

1> use dhrdb

2> go

1> create table t1(id int,name varchar(10))

2> go

1> sp_help t1

2> go

 Name Owner Object_type Object_status Create_date        

 ---- ----- ----------- ------------- -------------------

 t1   dbo   user table   -- none --   Jun 21 2022  8:53AM

 

(1 row affected)

 Column_name Type    Length Prec Scale Nulls Not_compressed Default_name

         Rule_name Access_Rule_name Computed_Column_object Identity  

 ----------- ------- ------ ---- ----- ----- -------------- ------------

         --------- ---------------- ---------------------- ----------

 id          int          4 NULL  NULL     0              0 NULL       

         NULL      NULL             NULL                            0

 name        varchar     10 NULL  NULL     0              0 NULL       

         NULL      NULL             NULL                            0

Object does not have any indexes.

No defined keys for this object.

 name type       partition_type partitions partition_keys

 ---- ---------- -------------- ---------- --------------

 t1   base table roundrobin              1 NULL          

 

 partition_name partition_id compression_level pages row_count segment

         create_date        

 -------------- ------------ ----------------- ----- --------- -------

         -------------------

 t1_608002166      608002166 none                  1         0 default

         Jun 21 2022  8:53AM

 

 Partition_Conditions

 --------------------

 NULL                

 

 Avg_pages   Max_pages   Min_pages   Ratio(Max/Avg)            

         Ratio(Min/Avg)             

 ----------- ----------- ----------- ---------------------------

         ---------------------------

           1           1           1                    1.000000

                            1.000000

Table LOB compression level 0

Lock scheme Datarows

The 'ascinserts' attribute is not applicable to tables with datarow or datapage

lock schemes.

 

 exp_row_size reservepagegap fillfactor max_rows_per_page identity_gap

         ascinserts 

 ------------ -------------- ---------- ----------------- ------------

         -----------

            0              0          0                 0            0

                   0

 

(1 row affected)

 concurrency_opt_threshold optimistic_index_lock dealloc_first_txtpg

         cached_index_root_page recompile_factor                     

         plldegree

 ------------------------- --------------------- -------------------

         ---------------------- --------------------------------------

         ---------

                        15                     0                   0

                              0 NULL                                 

                 0

(return status = 0)

 

 

 

1> insert into t1 values(10,'aa')

2> go

(1 row affected)

1> select * from t1

2> go

 id          name      

 ----------- ----------

          10 aa        

 

(1 row affected)

 

 

3.备份测试数据库

 

1> dump database dhrdb to "/sybase/T66/dhr/bk/dhrdb.dat"

2> go

Backup Server: 4.172.1.4: The value of 'allocated pages threshold' has been set

to 40%.

Backup Server session id is: 12. Use this value when executing the

'sp_volchanged' system stored procedure after fulfilling any volume change

request from the Backup Server.

Backup Server: 4.41.1.1: Creating new disk file /sybase/T66/dhr/bk/dhrdb.dat.

Backup Server: 6.28.1.1: Dumpfile name 'dhrdb2217300A21  ' section number 1

mounted on disk file '/sybase/T66/dhr/bk/dhrdb.dat'

Backup Server: 4.166.1.1: Using dbiosize of 131072 bytes for device

/sybase/T66/dhr/bk/dhrdb.dat.

Backup Server: 4.165.1.1: Using iocount of 2 for device

/sybase/T66/dhr/bk/dhrdb.dat.

Backup Server: 4.166.1.2: Using zonesize of 262144 bytes for device

/sybase/T66/dhr/bk/dhrdb.dat.

Backup Server: 4.166.1.3: Using blocksize of 65536 bytes for device

/sybase/T66/dhr/bk/dhrdb.dat.

Backup Server: 4.165.1.2: Using numzones of 3 for device

/sybase/T66/dhr/bk/dhrdb.dat.

Backup Server: 4.165.1.3: Using archcnt of 1 for device

/sybase/T66/dhr/bk/dhrdb.dat.

Backup Server: 4.165.1.4: Using dbdevcnt of 2 for device

/sybase/T66/dhr/bk/dhrdb.dat.

Backup Server: 4.166.1.4: Using pagesize of 16384 bytes for device

/sybase/T66/dhr/bk/dhrdb.dat.

Backup Server: 4.188.1.1: Database dhrdb: 2740 kilobytes (1%) DUMPED.

Backup Server: 4.188.1.1: Database dhrdb: 4630 kilobytes (13%) DUMPED.

Backup Server: 4.188.1.1: Database dhrdb: 5976 kilobytes (30%) DUMPED.

Backup Server: 4.188.1.1: Database dhrdb: 7322 kilobytes (46%) DUMPED.

Backup Server: 4.188.1.1: Database dhrdb: 8668 kilobytes (62%) DUMPED.

Backup Server: 4.188.1.1: Database dhrdb: 10014 kilobytes (79%) DUMPED.

Backup Server: 4.188.1.1: Database dhrdb: 11360 kilobytes (95%) DUMPED.

Backup Server: 4.188.1.1: Database dhrdb: 11794 kilobytes (100%) DUMPED.

Backup Server: 3.43.1.1: Dump phase number 1 completed.

Backup Server: 3.43.1.1: Dump phase number 2 completed.

Backup Server: 3.43.1.1: Dump phase number 3 completed.

Backup Server: 4.188.1.1: Database dhrdb: 11816 kilobytes (100%) DUMPED.

Backup Server: 3.42.1.1: DUMP is complete (database dhrdb).

 

4.模拟损坏:将测试数据库删除

 

1> drop database dhrdb

2> go

Processed 56 allocation unit(s) out of 512 units (allocation page 14080). 10%

completed.

Processed 104 allocation unit(s) out of 512 units (allocation page 26368). 20%

completed.

Processed 160 allocation unit(s) out of 512 units (allocation page 40704). 31%

completed.

Processed 216 allocation unit(s) out of 512 units (allocation page 55040). 42%

completed.

Processed 272 allocation unit(s) out of 512 units (allocation page 69376). 53%

completed.

Processed 328 allocation unit(s) out of 512 units (allocation page 83712). 64%

completed.

Processed 384 allocation unit(s) out of 512 units (allocation page 98048). 75%

completed.

Processed 440 allocation unit(s) out of 512 units (allocation page 112384). 85%

completed.

Processed 488 allocation unit(s) out of 512 units (allocation page 124672). 95%

completed.

Processed 512 allocation unit(s) out of 512 units (allocation page 130816). 100%

completed.

 

 

1> sp_helpdb  使用此命令可以确认数据库已经删除成功

2> go

 name           db_size       owner dbid  created      durability  lobcomplvl

         inrowlen

         status                                                                                                                                                                                                                                                           

 -------------- ------------- ----- ----- ------------ ----------- ----------

         --------

         ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 T66               70656.0 MB sapsa     4 May 09, 2022 full               100

             2000

         trunc log on chkpt, ddl in tran, allow nulls by default, abort tran on

         log full, allow db suspect on rollback error, allow wide dol rows, defe

         rred table allocation, page compression, allow incremental dumps, deall

         ocate first text page, full logging for all

 master              300.0 MB sa        1 May 09, 2022 full                 0

             NULL

         mixed log and data                                                                                                                                                                                                                                              

 model                24.0 MB sa        3 May 09, 2022 full                 0

             NULL

         mixed log and data                                                                                                                                                                                                                                               

 saptempdb          8192.0 MB sa        6 Jun 21, 2022 no_recovery          0

             NULL

         select into/bulkcopy/pllsort, trunc log on chkpt, ddl in tran, allow nu

         lls by default, abort tran on log full, mixed log and data, user create

         d temp db, allow wide dol rows                                                                                    

 saptools           8192.0 MB sapsa     5 May 09, 2022 full                 0

             NULL

         select into/bulkcopy/pllsort, trunc log on chkpt, ddl in tran, allow nu

         lls by default, abort tran on log full, allow db suspect on rollback er

         ror, allow wide dol rows, allow incremental dumps                                                                 

 sybcatdb           4048.0 MB sa        7 Jun 16, 2022 full                 0

             NULL

         select into/bulkcopy/pllsort, trunc log on chkpt                                                                                                                                                                                                                 

 sybmgmtdb           196.0 MB sa    31515 May 09, 2022 full                 0

             NULL

         select into/bulkcopy/pllsort, trunc log on chkpt                                                                                                                                                                                                                 

 sybsecurity        2560.0 MB sapsa 31516 May 09, 2022 full                 0

             NULL

         select into/bulkcopy/pllsort, trunc log on chkpt, ddl in tran                                                                                                                                                                                                   

 sybsystemdb          72.0 MB sa    31513 May 09, 2022 full                 0

             NULL

         trunc log on chkpt, mixed log and data                                                                                                                                                                                                                           

 sybsystemprocs      300.0 MB sa    31514 May 09, 2022 full                 0

             NULL

         trunc log on chkpt, mixed log and data                                                                                                                                                                                                                           

 tempdb             3096.0 MB sa        2 Jun 21, 2022 no_recovery          0

             NULL

         select into/bulkcopy/pllsort, trunc log on chkpt, ddl in tran, allow nu

         lls by default, mixed log and data, allow wide dol rows                                                                                                                                   

 

(1 row affected)

(return status = 0)

1>

 

 

5.恢复数据库

(1)在恢复数据库前需要确保已经存在空的数据库了

1> create database dhrdb                           

2> on dhrdata="1G"

3> log on dhrlog="1G"

4> Go

CREATE DATABASE: allocating 65536 logical pages (1024.0 megabytes) on disk

'dhrdata' (65536 logical pages requested).

CREATE DATABASE: allocating 65536 logical pages (1024.0 megabytes) on disk

'dhrlog' (65536 logical pages requested).

Processed 52 allocation unit(s) out of 512 units (allocation page 13056). 10%

completed.

Processed 103 allocation unit(s) out of 512 units (allocation page 26112). 20%

completed.

Processed 154 allocation unit(s) out of 512 units (allocation page 39168). 30%

completed.

Processed 205 allocation unit(s) out of 512 units (allocation page 52224). 40%

completed.

Processed 256 allocation unit(s) out of 512 units (allocation page 65280). 50%

completed.

Processed 308 allocation unit(s) out of 512 units (allocation page 78592). 60%

completed.

Processed 359 allocation unit(s) out of 512 units (allocation page 91648). 70%

completed.

Processed 410 allocation unit(s) out of 512 units (allocation page 104704). 80%

completed.

Processed 461 allocation unit(s) out of 512 units (allocation page 117760). 90%

completed.

Processed 512 allocation unit(s) out of 512 units (allocation page 130816). 100%

completed.

Database 'dhrdb' is now online.

 

(2)使用load database命令恢复数据库

1> load database dhrdb from "/sybase/T66/dhr/bk/dhrdb.dat"

2> go

Backup Server session id is: 16. Use this value when executing the

'sp_volchanged' system stored procedure after fulfilling any volume change

request from the Backup Server.

Backup Server: 6.28.1.1: Dumpfile name 'dhrdb2217300A21  ' section number 1

mounted on disk file '/sybase/T66/dhr/bk/dhrdb.dat'

Backup Server: 4.166.1.1: Using dbiosize of 131072 bytes for device

/sybase/T66/dhr/bk/dhrdb.dat.

Backup Server: 4.165.1.1: Using iocount of 2 for device

/sybase/T66/dhr/bk/dhrdb.dat.

Backup Server: 4.166.1.2: Using zonesize of 262144 bytes for device

/sybase/T66/dhr/bk/dhrdb.dat.

Backup Server: 4.166.1.3: Using blocksize of 65536 bytes for device

/sybase/T66/dhr/bk/dhrdb.dat.

Backup Server: 4.165.1.2: Using numzones of 3 for device

/sybase/T66/dhr/bk/dhrdb.dat.

Backup Server: 4.165.1.3: Using archcnt of 1 for device

/sybase/T66/dhr/bk/dhrdb.dat.

Backup Server: 4.165.1.4: Using dbdevcnt of 2 for device

/sybase/T66/dhr/bk/dhrdb.dat.

Backup Server: 4.166.1.4: Using pagesize of 16384 bytes for device

/sybase/T66/dhr/bk/dhrdb.dat.

Backup Server: 4.188.1.1: Database dhrdb: 266246 kilobytes (12%) LOADED.

Backup Server: 4.188.1.1: Database dhrdb: 610312 kilobytes (29%) LOADED.

Backup Server: 4.188.1.1: Database dhrdb: 954378 kilobytes (45%) LOADED.

Backup Server: 4.188.1.1: Database dhrdb: 1298444 kilobytes (61%) LOADED.

Backup Server: 4.188.1.1: Database dhrdb: 1642510 kilobytes (78%) LOADED.

Backup Server: 4.188.1.1: Database dhrdb: 1986576 kilobytes (94%) LOADED.

Backup Server: 4.188.1.1: Database dhrdb: 2097170 kilobytes (100%) LOADED.

Backup Server: 4.188.1.1: Database dhrdb: 2097192 kilobytes (100%) LOADED.

Backup Server: 3.42.1.1: LOAD is complete (database dhrdb).

Started estimating recovery log boundaries for database 'dhrdb'.

Database 'dhrdb', checkpoint=(65538, 107), first=(65538, 107), last=(65538,

110).

Completed estimating recovery log boundaries for database 'dhrdb'.

Started ANALYSIS pass for database 'dhrdb'.

Completed ANALYSIS pass for database 'dhrdb'.

Started REDO pass for database 'dhrdb'. The total number of log records to

process is 4.

Redo pass of recovery has processed 1 committed and 0 aborted transactions.

Completed REDO pass for database 'dhrdb'.

Use the ONLINE DATABASE command to bring this database online; ASE will not

bring it online automatically.

 

 

(3)数据库恢复完后是离线状态,需要手工online

1> use dhrdb

2> go

Msg 950, Level 14, State 1:

Server 'T66', Line 1:

Database 'dhrdb' is currently offline. Please wait and try your command again

later.

1>

 

 

1> online database dhrdb

2> go

Started estimating recovery log boundaries for database 'dhrdb'.

Database 'dhrdb', checkpoint=(65538, 107), first=(65538, 107), last=(65538,

110).

Completed estimating recovery log boundaries for database 'dhrdb'.

Started ANALYSIS pass for database 'dhrdb'.

Completed ANALYSIS pass for database 'dhrdb'.

Recovery of database 'dhrdb' will undo incomplete nested top actions.

Checking external objects.

Database 'dhrdb' is now online.

 

6.确认恢复后的数据

1> use dhrdb

2> go

 

 

1> select * from t1

2> go

 id          name      

 ----------- ----------

          10 aa        

 

(1 row affected)

 

 

1> select name from sysobjects where type='U'   这个命令是查看数据库中所有表

2> go

 name                                                                                                                                                                                                                                                            

 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 syb_auto_db_extend_control                                                                                                                                                                                                                                      

 t1                                                                                                                                                                                                                                                              

 

(2 rows affected)

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论