Locations of visitors to this page

Monday, December 29, 2008

new year's resolutions

new year's resolutions

database usage statistics - 数据库的使用统计信息

database usage statistics - 数据库的使用统计信息



1.
DBA_FEATURE_USAGE_STATISTICS 视图显示了数据库中各个特性的使用情况,比如哪种特性被使用了多少次,最近使用时间等. 10gR1新增
set pages 9999 line 120
col name for a50
select * from dba_feature_usage_statistics;
SQL> select * from dba_feature_usage_statistics;

DBID NAME VERSION DETECTED_USAGES TOTAL_SAMPLES CURRE
---------- -------------------------------------------------- ----------------- --------------- ------------- -----
FIRST_USAGE_DATE LAST_USAGE_DATE AUX_COUNT
------------------- ------------------- ----------
FEATURE_INFO LAST_SAMPLE_DATE LAST_SAMPLE_PERIOD
-------------------------------------------------------------------------------- ------------------- ------------------
SAMPLE_INTERVAL
---------------
DESCRIPTION
------------------------------------------------------------------------------------------------------------------------
1955690436 Advanced Replication 10.2.0.4.0 0 28 FALSE

2008-12-25 23:35:42 604800
604800
Advanced Replication has been enabled.

...
1955690436 Automatic Undo Management 10.2.0.4.0 28 28 TRUE
2008-06-16 12:18:20 2008-12-25 23:35:42 1
(Retention: NOGUARANTEE, TS Count: 1, Size MB: 24) (Undo Blo 2008-12-25 23:35:42 604800
cks: 31841, Max Concurrency: 5) (Snapsho
t Old Info - Begin Time: 2008-12-21 23:3
8:26, End Time: 2008-12-25 23:35:42, SSO
LD Error Count: 0)
604800
Oracle automatically manages undo data using an UNDO tablespace.

...
1955690436 PL/SQL Native Compilation 10.2.0.4.0 0 28 FALSE

2008-12-25 23:35:42 604800
604800
PL/SQL Native Compilation is being used - there is at least one natively compiled PL/SQL library unit in the database.


69 rows selected.

SQL>



2.
DBA_HIGH_WATER_MARK_STATISTICS 显示数据库中最高水位的统计信息,如表空间,文件,表等曾达到的最大值. 10gR1新增
select * from dba_high_water_mark_statistics;
SQL> select * from dba_high_water_mark_statistics;

DBID NAME VERSION HIGHWATER LAST_VALUE
---------- -------------------------------------------------- ----------------- ---------- ----------
DESCRIPTION
------------------------------------------------------------------------------------------------------------------------
1955690436 ACTIVE_SESSIONS 10.2.0.4.0 0 0
Maximum Number of Active Sessions seen in the system

1955690436 CPU_COUNT 10.2.0.4.0 2 2
Maximum Number of CPUs

1955690436 DATAFILES 10.2.0.4.0 10 10
Maximum Number of Datafiles

1955690436 DB_SIZE 10.2.0.4.0 1.3285E+10 1967128576
Maximum Size of the Database (Bytes)

...
1955690436 USER_MV 10.2.0.4.0 6 4
Maximum Number of Materialized Views (User)

1955690436 USER_TABLES 10.2.0.4.0 316 316
Number of User Tables


15 rows selected.

SQL>


3.
DBA_CPU_USAGE_STATISTICS 显示中央处理器使用的统计信息. 10gR2新增
select * from dba_cpu_usage_statistics;
SQL> select * from dba_cpu_usage_statistics;

DBID VERSION TIMESTAMP CPU_COUNT CPU_CORE_COUNT CPU_SOCKET_COUNT
---------- ----------------- ------------------- ---------- -------------- ----------------
1955690436 10.2.0.4.0 2008-06-16 12:18:20 2 1

SQL>

视图1.2.3.的数据源是自动工作负载信息库(AWR)中的一些以wri$开头的表(AWR Internal tables)
DBMS_FEATURE_USAGE 注册特性, DBMS_FEATURE_USAGE_REPORT 生成报告


4.
V$OPTION 列出数据库软件安装了哪些选项(option)以及具有哪些特性(feature)
col parameter for a40
select * from v$option;
SQL> select * from v$option;

PARAMETER VALUE
---------------------------------------- ----------------------------------------------------------------
Partitioning TRUE
Objects TRUE
Real Application Clusters FALSE
Advanced replication TRUE
Bit-mapped indexes TRUE
Connection multiplexing TRUE
Connection pooling TRUE
...
Data Mining Scoring Engine FALSE
Transparent Data Encryption TRUE
Backup Encryption TRUE
Unused Block Compression TRUE
Oracle Database Vault FALSE
Real Application Testing TRUE

56 rows selected.

SQL>


5.
DBA_REGISTRY 显示了数据库加载了哪些组件(component),这是数据库级的. 9i新增.
select * from dba_registry;
SQL> select * from dba_registry;

COMP_ID
------------------------------
COMP_NAME
------------------------------------------------------------------------------------------------------------------------
VERSION STATUS MODIFIED
------------------------------ -------------------------------------------- -----------------------------
NAMESPACE CONTROL SCHEMA
------------------------------ ------------------------------ ------------------------------
PROCEDURE STARTUP PARENT_ID
------------------------------------------------------------- -------- ------------------------------
OTHER_SCHEMAS
------------------------------------------------------------------------------------------------------------------------
CONTEXT
Oracle Text
10.2.0.4.0 VALID 17-JUN-2008 01:55:34
SERVER SYS CTXSYS
VALIDATE_CONTEXT


OWM
Oracle Workspace Manager
10.2.0.4.3 VALID 16-JUN-2008 11:17:38
SERVER SYS WMSYS
VALIDATE_OWM


CATALOG
Oracle Database Catalog Views
10.2.0.4.0 VALID 16-JUN-2008 11:16:44
SERVER SYS SYS
DBMS_REGISTRY_SYS.VALIDATE_CATALOG


CATPROC
Oracle Database Packages and Types
10.2.0.4.0 VALID 16-JUN-2008 11:16:44
SERVER SYS SYS
DBMS_REGISTRY_SYS.VALIDATE_CATPROC
DBSNMP,OUTLN,SYSTEM


SQL>


6.
V$LICENSE 包括了许可限制信息,如实例中用户会话数和中央处理器数的最大值,当前值和最高水位值
select * from v$license;
SQL> select * from v$license;

SESSIONS_MAX SESSIONS_WARNING SESSIONS_CURRENT SESSIONS_HIGHWATER USERS_MAX CPU_COUNT_CURRENT CPU_CORE_COUNT_CURRENT
------------ ---------------- ---------------- ------------------ ---------- ----------------- ----------------------
CPU_SOCKET_COUNT_CURRENT CPU_COUNT_HIGHWATER CPU_CORE_COUNT_HIGHWATER CPU_SOCKET_COUNT_HIGHWATER
------------------------ ------------------- ------------------------ --------------------------
0 0 3 13 0 2
1 2 1


SQL>


7.
V$RESOURCE_LIMIT 显示出资源使用情况,包括初始值,当前值,最大值和最高限制
select * from v$resource_limit;
SQL> select * from v$resource_limit;

RESOURCE_NAME CURRENT_UTILIZATION MAX_UTILIZATION INITIAL_ALLOCATION
------------------------------ ------------------- --------------- ----------------------------------------
LIMIT_VALUE
----------------------------------------
processes 22 35 1500
1500

sessions 26 45 1655
1655

...
max_shared_servers 1 1 UNLIMITED
UNLIMITED

parallel_max_servers 0 0 40
3600


22 rows selected.

SQL>


外部链接:
Checking Database Feature Usage Stats
Hidden Costs
Remote Diagnostic Agent (RDA) 4 - Content Modules Man Page



-fin-

Wednesday, December 24, 2008

1z0-043 lesson 3 Using Recovery Manager

Update 5:
增加注释

Update 4:
增加显示选项

Update 3:
增加答案
增加29,30两道题


 是否显示我的答案
 是否显示书上的答案和我的注释

预留


Updated at 5.55PM on Dec. 24, 2008
考题

1.
6、Exhibit,
[1z0-043-lesson3-q01.png]
1z0-043-lesson3-q01.png
You executed the following command to perform a backup of the USERS tablespace:
RMAN > BACKUP TABLESPACE USERS;
Which type of backup would this command perform?
A. backup set
B. image copy
C. incremental backup
D. None; the user receives an error indicating that the backup type must be specified.
1.A
6.A
配置了device type ... backup to backupset



2.
32. You executed the following command in Recovery Manager (RMAN) against your Oracle 10g database:
RMAN> REPORT NEED BACKUP days 3;
What would be the output of this command?
A. a list of files that require a backup within three days
B. a list of files that have not been backed up for three days
C. a list of files that RMAN recommends be backed up only once in every three days, based on low volatility
D. a list of files for which a backup has already been performed and may need a backup after three days
2.B
32.B
教材3-31


3.
87. What purpose would you achieve by enabling the block change tracking feature?
A. Eliminate the necessity for backups.
B. Perform optimized image copy backups.
C. Perform optimized incremental backups.
D. Enable checkpoint (CKPT) to perform checkpointing at every block change.
E. Enable database writer (DBWn) to write changed blocks to data files faster.
3.C
87.C
教材3-25


4.
88. You execute the following RMAN command in the order shown below:
BACKUP VALIDATE DATABASE;
BLOCKRECOVER CORRUPTION LIST;
What will these commands do?
A. Create a backup of the database and recover all corrupted blocks found in the backup.
B. Run a backup validation and list all the logically corrupt blocks as well as physically corrupt blocks in the database.
C. Run a backup validation to populate V$COPY_CORRUPTION view, and then list any corrupt blocks recorded in the view.
D. Run a backup validation to populate V$DATABASE_BLOCK_CORRUPTION view, and then repair any corrupt blocks recorded in the view.
E. Run a backup validation, repair any corrupt blocks found during the validation process,
and then update V$DATABASE_BLOCK_CORRUPTION view to indicate which corrupt blocks have been repaired.
4.D 不知道BLOCKRECOVER做什么, 猜的
88.D
VALIDATE见教材3-21
BLOCKRECOVER这章没讲


5.
155. Which two statements regarding compressed backups in Recovery Manager (RMAN) are true? (Choose two.)
A. Backup compression is disabled by default.
B. Backup compression can be used with both backup sets and image copies.
C. Backup compression cannot be enabled using the CONFIGURE command.
D. Backup compression works only if the COMPATIBILITY parameter is set to 9.0.0.0 or higher.
E. Backup compression applies to only backup sets.
F. Backup compression applies to only image copies.
5.AE
155.AE
教材3-13


6.
163. You are managing a database for which incremental backups can be very time consuming.
In order to perform optimized incremental backups you enable the block change tracking feature.
How would you instruct RMAN to use the block change tracking feature when performing incremental backups?
A. You need to mention it with every BACKUP command.
B. The block change tracking feature is used automatically by RMAN.
C. You need to configure it using the CONFIGURE command.
D. You need to set the necessary initialization parameters to direct RMAN to use the feature.
6.B
163.B
教材3-25


7.
179. The backup retention policy is configured as RECOVERY WINDOW 2. You executed
the following command in Recovery Manager (RMAN) against your database:
RMAN> REPORT OBSOLETE;
What would you see in the output?
A. a list of all those files that have been deleted in the last two days
B. a list of all those files that have been recovered within the last two days
C. a list of all the expired backups and copies
D. a list of backups and copies that are outside the range covered by the current retention policy
7.D
179.D
教材3-31


8.
181. View the Exhibit.
[1z0-043-lesson3-q08.png]
1z0-043-lesson3-q08
You executed the following command to perform a backup of the USERS tablespace:
RMAN> BACKUP TABLESPACE USERS;
Which three types of files are backed up? (Choose three.)
A. all the data files belonging to the USERS tablespace
B. password file
C. online redo log files
D. the current control file
E. archived redo log files
F. the current server parameter file
G. data files belonging to the USERS tablespace and all the default tablespaces
8.ADF
181.ADF
配置了控制文件自动备份, 也自动备spfile

==========

9.
1. How is block change tracking enabled?
A. With ALTER DATABASE ENABLE BLOCK CHANGE TRACKING
B. With ALTER SYSTEM ENABLE BLOCK CHANGE TRACKING
C. With a INIT.ORA parameter change
D. With a SPFILE parameter change
9.A
3-26页
1. A. Block change tracking must be enabled with ALTER DATABASE ENABLE BLOCK CHANGE
TRACKING. The physical location and name of the block change tracking file must be supplied.


10.
2. What type of backup is stored in a proprietary RMAN format?
A. Backup set
B. Image copy
C. Backup section
D. Backup group
10.A
教材3-9
2. A. The backup set is stored in a proprietary RMAN format, where only used blocks are backed up.


11.
3. What method is used to improve backup performance when creating backup sets?
A. Multicopy
B. Multiplecopy
C. Multiplex
D. Multiply
11.C
3. 没说, 就是PARALLELISM吧
C. Multiplexing a backup is designed to improve the performance of the backup sets by copy-
ing multiple database files at the same time. Multiplexing can be used with image copies or
backup sets.


12.
4. Which command creates an image copy?
A. BACKUP AS COPY
B. BACKUP COPY
C. COPY AS BACKUP
D. COPY BACK
12.A
教材3-14
4. A. The BACKUP AS COPY command is used to create an image copy backup.


13.
5. Compressed backups work with which of the following commands?
A. COPY AS BACKUP
B. BACKUP AS COPY
C. BACKUP
D. COPY
13.C
教材3-13
5. C. Compressed backups work only with backup sets, not image copies. Thus compressed backups
will work only with the BACKUP command.


14.
6. What ratio are compressed backups sized to?
A. 30 percent
B. 40 percent
C. 70 percent
D. 20 percent
14.C 压缩率?不知道
压缩后是1/5? 不相信
6. D. Compressed backups compressed at a ratio of 5 to 1—20 percent—of the original size of a
standard backup.


15.
7. Which of the following best describes a full backup?
A. All datafiles of a database
B. All datafiles, archive logs, and control files
C. All datafiles and control files
D. All the used blocks in a datafile
15.A ?
见教材3-22
7. D. A full backup is best described by backing up all the used blocks in a datafile or any database
file. A full backup can be taken on one database file.


16.
8. Which type of backup backs up only data blocks modified since the most recent backup at the
same level or lower?
A. Differential incremental backup
B. Different incremental backup
C. Cumulative backup
D. Cumulative incremental backup
16.A
教材3-24
8. A. A differential incremental backup only backs up blocks that have been modified since a
backup at the same level or lower.


17.
9. Which type of backup must be performed first with an incremental backup?
A. Level 1
B. Level 0
C. Level 2
D. Level 3
17.B
教材3-22
9. B. A level 0 backup is the first backup that is performed when implementing an incremental
backup strategy. A level 0 backup copies all the used blocks as a baseline.


18.
10. Which backup option defines a user-defined name for a backup?
A. FORMAT
B. NAME
C. TAG
D. FORMAT U%
18.C ? A是起文件名
教材3-16
10. C. The TAG option is used to name a backup with a user-defined character string.


19.
11. What action requires the RESTORE command?
A. Restoring a backup set
B. Restoring an image copy
C. Performing all RMAN recovery processes
D. All of the above
19.D 觉得C不对, 是AB, 可是不能多选
image copy也可以restore, 也可以switch, 所以restore不是必须的
题出的不好
11. A. The RESTORE command is required only with a backup set recovery. This is because the
backup set is stored in a RMAN proprietary format.


20.
12. Which of the following most closely represents an image copy?
A. Unix cp command of a file
B. Bit-by-bit copy of a file
C. Windows COPY command of a file
D. All of the above
20.D
等于复制
12. D. Image copies are similar to operating system copy commands. These equate to bit-by-bit copies
of a file.


21.
13. Which dynamic view displays the status of block change tracking?
A. V$BLOCK_CHANGE
B. V$BLOCK_CHANGE_TRACKING
C. V$BLOCKCHANGE
D. V$BLOCK_TRACKING
21.B 瞎选的
教材3-26
13. B. The V$BLOCK_CHANGE_TRACKING dynamic view shows the filename, status, and size of the
block change tracking file.


22.
14. Which new Oracle 10g capability improves the backup efficency database of any size?
A. Differential incremental backup
B. Cumulative incremental backup
C. Block change tracking
D. Compressed backup
22.D
看错了, 压缩节省空间, 时间更长
14. C. Block change tracking improves the backup efficiency of large or small databases. With block
change tracking, the backup time is proportional to the amount of changes that occurred in a
database.


23.
15. Where are RMAN dynamic views stored?
A. Recovery catalog database
B. Control file of the recovery catalog database
C. Control file of the target database
D. Target database
23.C
这题不对吧 ,教材3-34 说放在控制文件中
15. D. RMAN dynamic views are stored in the target database.


24.
16. Which of the following can be used to monitor RMAN backups?
A. LIST commands
B. REPORT commands
C. RMAN dynamic views
D. All of the above
24.D
都看
16. D. LIST, REPORT, and dynamic views all allow different types of monitoring of RMAN activities.


25.
17. The LIST commands are best used to identify what about RMAN?
A. How many times the database is restored
B. Files impacted by the CHANGE, CROSSCHECK, and DELETE commands
C. Only data in the recovery catalog
D. All of the above
25.B
教材3-28
17. B. The LIST commands are used to determine files impacted by the CHANGE, CROSSCHECK, and
DELETE commands.


26.
18. The REPORT command is best used to identify what about RMAN?
A. Which files need a backup
B. Unneeded backups
C. Database physical schema
D. If unrecoverable operations were performed on files
E. All of the above
26.E
教材3-29
18. E. The REPORT command is best used to identify which files need a backup, unneeded backups,
database physical schema, and if unrecoverable operations were performed on files.


27.
19. What should be done to generate accurate information from the REPORT command?
A. Recently performed CHANGE command
B. Recently performed UNCATALOG command
C. Recently performed CROSSCHECK commands
D. RMAN repository synchronized with the control file
E. All of the above
27.E
教材3-29
19. E. The REPORT command is accurate when the control and RMAN repository are synchronized,
which can be performed by the CHANGE, UNCATALOG, and CROSSCHECK commands.


28.
20. Identify the methods used to schedule a backup job. (Choose all that apply.)
A. A third-party GUI tool provided by the media management provider
B. A file that is scheduled with the operating system scheduler
C. Running the EM Maintenance utility
D. Running RMAN from CLI
28.ABC
EM为什么不行?
20. A, B. Third-party GUI tools provided from the media manager software and manually scripting
a file incorporated with operating system scheduler are the two methods for scheduling a
backup.


29.
5. The BACKUP command has the ability to do what? (Choose all that apply.)
A. The BACKUP command can make bit-for-bit copies of a file.
B. The BACKUP command can improve performance by multiplexing backup files.
C. The BACKUP can take advantage of the block change tracking capability.
D. The BACKUP command cannot store data in incremental backups.
E. The BACKUP command can store data in cumulative incremental backups only.
29.ABC
A也可以呀, BACKUP AS COPY
5. B, C. The BACKUP command can take advantage of multiplexing datafiles to the same backup
set. The BACKUP command can also use the block change tracking capability. See Chapter 2 for
more information.


30.
6. Which commands are required to perform a compressed RMAN backup? (Choose all that apply.)
A. BACKUP AS COMPRESSED BACKUPSET DATABASE
B. BACKUP AS COMPRESSED COPY OF DATABASE
C. CONFIGURE DEVICE TYPE DISK BACKUP TYPE TO COMPRESSED BACKUPSET
D. CONFIGURE DEVICE TYPE DISK BACKUP TYPE COMPRESS
E. BACKUP DATABASE COMPRESS
30.AC
教材3-13
6. A, C. The correct methods of compressing a backup are to use the command BACKUP AS
COMPRESSED BACKUPSET DATABASE and to set persistent settings by using CONFIGURE DEVICE
TYPE DISK BACKUP TYPE TO COMPRESSED BACKUPSET. See Chapter 2 for more information.


Updated at 10:44 PM on Dec. 25, 2008
疑问

1. 3-10
If the target database is in ARCHIVELOG mode, only “current” data files can be backed up (restored data files are made current by recovery).
什么叫"current" data files?

2. 3-17
NOCHECKSUM, CHECK LOGICAL, VALIDATE 是什么意思?
NOCHECKSUM: 备份时不计算数据块的校验值?
CHECK LOGICAL:只检查逻辑错误(比如数据块的内部数据结构有问题?),不检查物理错误(读不出来?)?
VALIDATE: 假装备份一遍?





-fin-

introduction to BTRFS - BTRFS文件系统简单介绍

introduction to btrfs


Btrfs文件系统(B-tree FS, Butter-FS)是2007年oracle公司给linux开发的下一代文件系统,
采用了B-tree结构, 文件以盘区(extent)的方式进行分配,
支持子卷, 可写快照(writable snapshot), 快照的快照(snapshot of snapshot),
支持压缩, 动态分配, 支持多设备影射和RAID, 对象级的镜像和条带化,
支持快速离线文件系统检查, 在线碎片整理, 数据和元数据校验等特性
问题也很多, 比如格式没有最终确定, 不支持directio, aio, 不能处理磁盘满, 不能删除快照等
现在仍处于开发阶段,预计未来将会加到Linux内核中


安装一个试试:

1. 下载btrfs

mkdir -p /data/root/btrfs
cd /data/root/btrfs
[root@Perf-pxy-2 ~]# mkdir -p /data/root/btrfs
[root@Perf-pxy-2 ~]# cd /data/root/btrfs
[root@Perf-pxy-2 /data/root/btrfs]#


下载稳定版, v0.16版
wget http://www.kernel.org/hg/index.cgi/btrfs/kernel/archive/tip.tar.gz \
http://www.kernel.org/hg/index.cgi/btrfs/progs/archive/tip.tar.gz
[root@Perf-pxy-2 /data/root/btrfs]# wget http://www.kernel.org/hg/index.cgi/btrfs/kernel/archive/tip.tar.gz \
> http://www.kernel.org/hg/index.cgi/btrfs/progs/archive/tip.tar.gz
--14:41:42-- http://www.kernel.org/hg/index.cgi/btrfs/kernel/archive/tip.tar.gz
Resolving www.kernel.org... 199.6.1.164, 204.152.191.37, 130.239.17.4, ...
Connecting to www.kernel.org|199.6.1.164|:80... connected.
HTTP request sent, awaiting response... 200 Script output follows
Length: unspecified [application/x-tar]
Saving to: `kernel-417d87e57364.tar.gz'

[ <=> ] 174,542 79.4K/s in 2.1s

14:41:46 (79.4 KB/s) - `kernel-417d87e57364.tar.gz' saved [174542]

--14:41:46-- http://www.kernel.org/hg/index.cgi/btrfs/progs/archive/tip.tar.gz
Connecting to www.kernel.org|199.6.1.164|:80... connected.
HTTP request sent, awaiting response... 200 Script output follows
Length: unspecified [application/x-tar]
Saving to: `progs-da35ab2b0b54.tar.gz'

[ <=> ] 127,430 69.6K/s in 1.8s

14:41:48 (69.6 KB/s) - `progs-da35ab2b0b54.tar.gz' saved [127430]

FINISHED --14:41:48--
Downloaded: 2 files, 295K in 3.9s (75.0 KB/s)
[root@Perf-pxy-2 /data/root/btrfs]#
ls -l
[root@Perf-pxy-2 /data/root/btrfs]# ls -l
total 308
-rw-r--r-- 1 root root 174542 Dec 22 14:41 kernel-417d87e57364.tar.gz
-rw-r--r-- 1 root root 127430 Dec 22 14:41 progs-da35ab2b0b54.tar.gz

解压
tar zxf kernel-417d87e57364.tar.gz
tar zxf progs-da35ab2b0b54.tar.gz
[root@Perf-pxy-2 /data/root/btrfs]# tar zxf kernel-417d87e57364.tar.gz
[root@Perf-pxy-2 /data/root/btrfs]# tar zxf progs-da35ab2b0b54.tar.gz
[root@Perf-pxy-2 /data/root/btrfs]#

不稳定版本:
http://git.kernel.org/?p=linux/kernel/git/mason/btrfs-unstable.git;a=summary
http://git.kernel.org/?p=linux/kernel/git/mason/btrfs-unstable-standalone.git;a=summary
http://git.kernel.org/?p=linux/kernel/git/mason/btrfs-progs-unstable.git;a=summary
用git下载
git clone http://www.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-unstable-standalone.git
git clone http://www.kernel.org/pub/scm/linux/kernel/git/mason/btrfs-progs-unstable.git


2. 安装相关的rpm包

rpm -Uvh http://192.168.11.16/CentOS-5.2-x86_64-bin-DVD/CentOS/e2fsprogs-devel-1.39-15.el5.x86_64.rpm
[root@Perf-pxy-2 ~]# rpm -Uvh http://192.168.11.16/CentOS-5.2-x86_64-bin-DVD/CentOS/e2fsprogs-devel-1.39-15.el5.x86_64.rpm
Retrieving http://192.168.11.16/CentOS-5.2-x86_64-bin-DVD/CentOS/e2fsprogs-devel-1.39-15.el5.x86_64.rpm
warning: /var/tmp/rpm-xfer.0N0GT2: Header V3 DSA signature: NOKEY, key ID e8562897
Preparing... ########################################### [100%]
1:e2fsprogs-devel ########################################### [100%]
[root@Perf-pxy-2 ~]#

rpm -Uvh http://192.168.11.16/CentOS-5.2-x86_64-bin-DVD/CentOS/libattr-devel-2.4.32-1.1.x86_64.rpm
rpm -Uvh http://192.168.11.16/CentOS-5.2-x86_64-bin-DVD/CentOS/libacl-devel-2.2.39-3.el5.x86_64.rpm

[root@Perf-pxy-2 ~]# rpm -Uvh http://192.168.11.16/CentOS-5.2-x86_64-bin-DVD/CentOS/libattr-devel-2.4.32-1.1.x86_64.rpm
Retrieving http://192.168.11.16/CentOS-5.2-x86_64-bin-DVD/CentOS/libattr-devel-2.4.32-1.1.x86_64.rpm
warning: /var/tmp/rpm-xfer.qz4sPQ: Header V3 DSA signature: NOKEY, key ID e8562897
Preparing... ########################################### [100%]
1:libattr-devel ########################################### [100%]
[root@Perf-pxy-2 ~]# rpm -Uvh http://192.168.11.16/CentOS-5.2-x86_64-bin-DVD/CentOS/libacl-devel-2.2.39-3.el5.x86_64.rpm
Retrieving http://192.168.11.16/CentOS-5.2-x86_64-bin-DVD/CentOS/libacl-devel-2.2.39-3.el5.x86_64.rpm
warning: /var/tmp/rpm-xfer.1mMa05: Header V3 DSA signature: NOKEY, key ID e8562897
Preparing... ########################################### [100%]
1:libacl-devel ########################################### [100%]
[root@Perf-pxy-2 ~]#


3. 编译和安装

编译和安装内核模块
cd kernel-417d87e57364
make && make modules_install
ls -l /lib/modules/`uname -r`/extra/btrfs.ko
[root@Perf-pxy-2 /data/root/btrfs]# cd kernel-417d87e57364
[root@Perf-pxy-2 /data/root/btrfs/kernel-417d87e57364]#
[root@Perf-pxy-2 /data/root/btrfs/kernel-417d87e57364]# make && make modules_install
bash version.sh
which: no hg in (/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
make -C /lib/modules/`uname -r`/build M=`pwd` modules
make[1]: Entering directory `/usr/src/kernels/2.6.18-92.el5-x86_64'
CC [M] /data/root/btrfs/kernel-417d87e57364/super.o
CC [M] /data/root/btrfs/kernel-417d87e57364/ctree.o
CC [M] /data/root/btrfs/kernel-417d87e57364/extent-tree.o
CC [M] /data/root/btrfs/kernel-417d87e57364/print-tree.o
CC [M] /data/root/btrfs/kernel-417d87e57364/root-tree.o
CC [M] /data/root/btrfs/kernel-417d87e57364/dir-item.o
CC [M] /data/root/btrfs/kernel-417d87e57364/hash.o
CC [M] /data/root/btrfs/kernel-417d87e57364/file-item.o
CC [M] /data/root/btrfs/kernel-417d87e57364/inode-item.o
CC [M] /data/root/btrfs/kernel-417d87e57364/inode-map.o
CC [M] /data/root/btrfs/kernel-417d87e57364/disk-io.o
CC [M] /data/root/btrfs/kernel-417d87e57364/transaction.o
CC [M] /data/root/btrfs/kernel-417d87e57364/bit-radix.o
CC [M] /data/root/btrfs/kernel-417d87e57364/inode.o
CC [M] /data/root/btrfs/kernel-417d87e57364/file.o
CC [M] /data/root/btrfs/kernel-417d87e57364/tree-defrag.o
CC [M] /data/root/btrfs/kernel-417d87e57364/extent_map.o
CC [M] /data/root/btrfs/kernel-417d87e57364/sysfs.o
CC [M] /data/root/btrfs/kernel-417d87e57364/struct-funcs.o
CC [M] /data/root/btrfs/kernel-417d87e57364/xattr.o
CC [M] /data/root/btrfs/kernel-417d87e57364/ordered-data.o
CC [M] /data/root/btrfs/kernel-417d87e57364/extent_io.o
CC [M] /data/root/btrfs/kernel-417d87e57364/volumes.o
CC [M] /data/root/btrfs/kernel-417d87e57364/async-thread.o
CC [M] /data/root/btrfs/kernel-417d87e57364/ioctl.o
CC [M] /data/root/btrfs/kernel-417d87e57364/locking.o
CC [M] /data/root/btrfs/kernel-417d87e57364/orphan.o
CC [M] /data/root/btrfs/kernel-417d87e57364/ref-cache.o
CC [M] /data/root/btrfs/kernel-417d87e57364/acl.o
LD [M] /data/root/btrfs/kernel-417d87e57364/btrfs.o
Building modules, stage 2.
MODPOST
CC /data/root/btrfs/kernel-417d87e57364/btrfs.mod.o
LD [M] /data/root/btrfs/kernel-417d87e57364/btrfs.ko
make[1]: Leaving directory `/usr/src/kernels/2.6.18-92.el5-x86_64'
make -C /lib/modules/`uname -r`/build M=`pwd` modules_install
make[1]: Entering directory `/usr/src/kernels/2.6.18-92.el5-x86_64'
INSTALL /data/root/btrfs/kernel-417d87e57364/btrfs.ko
DEPMOD 2.6.18-92.el5
make[1]: Leaving directory `/usr/src/kernels/2.6.18-92.el5-x86_64'
[root@Perf-pxy-2 /data/root/btrfs/kernel-417d87e57364]#
[root@Perf-pxy-2 /data/root/btrfs/kernel-417d87e57364]# ls -l /lib/modules/`uname -r`/extra/btrfs.ko
-rw-r--r-- 1 root root 4571860 Dec 22 14:47 /lib/modules/2.6.18-92.el5/extra/btrfs.ko
[root@Perf-pxy-2 /data/root/btrfs/kernel-417d87e57364]#

make modules_install好像有点问题,所以再手工depmod一下
depmod
[root@Perf-pxy-2 ~]# depmod
[root@Perf-pxy-2 ~]#

编译和安装程序
cd ../progs-da35ab2b0b54
make && make convert && make install
ls -l /usr/local/bin/
[root@Perf-pxy-2 /data/root/btrfs/kernel-417d87e57364]# cd ../progs-da35ab2b0b54
[root@Perf-pxy-2 /data/root/btrfs/progs-da35ab2b0b54]#
[root@Perf-pxy-2 /data/root/btrfs/progs-da35ab2b0b54]# make && make convert && make install
bash version.sh
which: no hg in (/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin)
ls ctree.c
ctree.c
gcc -Wp,-MMD,./.ctree.o.d,-MT,ctree.o -Wall -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -g -Werror -Os -c ctree.c
ls disk-io.c
disk-io.c
gcc -Wp,-MMD,./.disk-io.o.d,-MT,disk-io.o -Wall -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -g -Werror -Os -c disk-io.c
ls radix-tree.c
radix-tree.c
gcc -Wp,-MMD,./.radix-tree.o.d,-MT,radix-tree.o -Wall -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -g -Werror -Os -c radix-tree.c
ls extent-tree.c
extent-tree.c
gcc -Wp,-MMD,./.extent-tree.o.d,-MT,extent-tree.o -Wall -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -g -Werror -Os -c extent-tree.c
ls print-tree.c
print-tree.c
gcc -Wp,-MMD,./.print-tree.o.d,-MT,print-tree.o -Wall -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -g -Werror -Os -c print-tree.c
ls root-tree.c
root-tree.c
gcc -Wp,-MMD,./.root-tree.o.d,-MT,root-tree.o -Wall -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -g -Werror -Os -c root-tree.c
ls dir-item.c
dir-item.c
gcc -Wp,-MMD,./.dir-item.o.d,-MT,dir-item.o -Wall -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -g -Werror -Os -c dir-item.c
ls hash.c
hash.c
gcc -Wp,-MMD,./.hash.o.d,-MT,hash.o -Wall -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -g -Werror -Os -c hash.c
ls file-item.c
file-item.c
gcc -Wp,-MMD,./.file-item.o.d,-MT,file-item.o -Wall -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -g -Werror -Os -c file-item.c
ls inode-item.c
inode-item.c
gcc -Wp,-MMD,./.inode-item.o.d,-MT,inode-item.o -Wall -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -g -Werror -Os -c inode-item.c
ls inode-map.c
inode-map.c
gcc -Wp,-MMD,./.inode-map.o.d,-MT,inode-map.o -Wall -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -g -Werror -Os -c inode-map.c
ls crc32c.c
crc32c.c
gcc -Wp,-MMD,./.crc32c.o.d,-MT,crc32c.o -Wall -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -g -Werror -Os -c crc32c.c
ls rbtree.c
rbtree.c
gcc -Wp,-MMD,./.rbtree.o.d,-MT,rbtree.o -Wall -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -g -Werror -Os -c rbtree.c
ls extent-cache.c
extent-cache.c
gcc -Wp,-MMD,./.extent-cache.o.d,-MT,extent-cache.o -Wall -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -g -Werror -Os -c extent-cache.c
ls extent_io.c
extent_io.c
gcc -Wp,-MMD,./.extent_io.o.d,-MT,extent_io.o -Wall -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -g -Werror -Os -c extent_io.c
ls volumes.c
volumes.c
gcc -Wp,-MMD,./.volumes.o.d,-MT,volumes.o -Wall -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -g -Werror -Os -c volumes.c
ls utils.c
utils.c
gcc -Wp,-MMD,./.utils.o.d,-MT,utils.o -Wall -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -g -Werror -Os -c utils.c
ls btrfsctl.c
btrfsctl.c
gcc -Wp,-MMD,./.btrfsctl.o.d,-MT,btrfsctl.o -Wall -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -g -Werror -Os -c btrfsctl.c
gcc -g -Werror -Os -o btrfsctl btrfsctl.o ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o root-tree.o dir-item.o hash.o file-item.o inode-item.o inode-map.o crc32c.o rbtree.o extent-cache.o extent_io.o volumes.o utils.o -luuid
ls btrfsck.c
btrfsck.c
gcc -Wp,-MMD,./.btrfsck.o.d,-MT,btrfsck.o -Wall -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -g -Werror -Os -c btrfsck.c
ls bit-radix.c
bit-radix.c
gcc -Wp,-MMD,./.bit-radix.o.d,-MT,bit-radix.o -Wall -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -g -Werror -Os -c bit-radix.c
gcc -g -Werror -Os -o btrfsck btrfsck.o ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o root-tree.o dir-item.o hash.o file-item.o inode-item.o inode-map.o crc32c.o rbtree.o extent-cache.o extent_io.o volumes.o utils.o bit-radix.o -luuid
ls mkfs.c
mkfs.c
gcc -Wp,-MMD,./.mkfs.o.d,-MT,mkfs.o -Wall -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -g -Werror -Os -c mkfs.c
gcc -g -Werror -Os -o mkfs.btrfs ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o root-tree.o dir-item.o hash.o file-item.o inode-item.o inode-map.o crc32c.o rbtree.o extent-cache.o extent_io.o volumes.o utils.o mkfs.o -luuid
ls debug-tree.c
debug-tree.c
gcc -Wp,-MMD,./.debug-tree.o.d,-MT,debug-tree.o -Wall -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -g -Werror -Os -c debug-tree.c
gcc -g -Werror -Os -o debug-tree ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o root-tree.o dir-item.o hash.o file-item.o inode-item.o inode-map.o crc32c.o rbtree.o extent-cache.o extent_io.o volumes.o utils.o debug-tree.o -luuid
ls btrfs-show.c
btrfs-show.c
gcc -Wp,-MMD,./.btrfs-show.o.d,-MT,btrfs-show.o -Wall -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -g -Werror -Os -c btrfs-show.c
gcc -g -Werror -Os -o btrfs-show btrfs-show.o ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o root-tree.o dir-item.o hash.o file-item.o inode-item.o inode-map.o crc32c.o rbtree.o extent-cache.o extent_io.o volumes.o utils.o -luuid
ls btrfs-vol.c
btrfs-vol.c
gcc -Wp,-MMD,./.btrfs-vol.o.d,-MT,btrfs-vol.o -Wall -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -g -Werror -Os -c btrfs-vol.c
gcc -g -Werror -Os -o btrfs-vol btrfs-vol.o ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o root-tree.o dir-item.o hash.o file-item.o inode-item.o inode-map.o crc32c.o rbtree.o extent-cache.o extent_io.o volumes.o utils.o -luuid
ls convert.c
convert.c
gcc -Wp,-MMD,./.convert.o.d,-MT,convert.o -Wall -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -g -Werror -Os -c convert.c
gcc -g -Werror -Os -o btrfs-convert ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o root-tree.o dir-item.o hash.o file-item.o inode-item.o inode-map.o crc32c.o rbtree.o extent-cache.o extent_io.o volumes.o utils.o convert.o -lext2fs -luuid
install -m755 -d /usr/local/bin
install btrfsctl btrfsck mkfs.btrfs debug-tree btrfs-show btrfs-vol /usr/local/bin
if [ -e btrfs-convert ]; then install btrfs-convert /usr/local/bin; fi
[root@Perf-pxy-2 /data/root/btrfs/progs-da35ab2b0b54]#
[root@Perf-pxy-2 /data/root/btrfs/progs-da35ab2b0b54]# ls -l /usr/local/bin/
total 3464
-rwxr-xr-x 1 root root 512210 Dec 22 15:05 btrfsck
-rwxr-xr-x 1 root root 569484 Dec 22 15:05 btrfs-convert
-rwxr-xr-x 1 root root 479349 Dec 22 15:05 btrfsctl
-rwxr-xr-x 1 root root 482791 Dec 22 15:05 btrfs-show
-rwxr-xr-x 1 root root 479228 Dec 22 15:05 btrfs-vol
-rwxr-xr-x 1 root root 486578 Dec 22 15:05 debug-tree
-rwxr-xr-x 1 root root 493286 Dec 22 15:05 mkfs.btrfs
[root@Perf-pxy-2 /data/root/btrfs/progs-da35ab2b0b54]#


4. 加载内核模块
modprobe btrfs
[root@Perf-pxy-2 ~]# modprobe btrfs
[root@Perf-pxy-2 ~]#

insmod /lib/modules/`uname -r`/extra/btrfs.ko

lsmod |grep btrfs
[root@Perf-pxy-2 ~]# lsmod |grep btrfs
btrfs 324936 0
[root@Perf-pxy-2 ~]#

配置系统启动自动加载
cat >/etc/sysconfig/modules/btrfs.modules <<'EOF'
#!/bin/sh
modprobe btrfs >/dev/null 2>&1
EOF
chmod 755 /etc/sysconfig/modules/btrfs.modules
ls -l /etc/sysconfig/modules/btrfs.modules
[root@Perf-pxy-2 ~]# cat >/etc/sysconfig/modules/btrfs.modules <<'EOF'
> #!/bin/sh
> modprobe btrfs >/dev/null 2>&1
> EOF
[root@Perf-pxy-2 ~]# chmod 755 /etc/sysconfig/modules/btrfs.modules
[root@Perf-pxy-2 ~]# ls -l /etc/sysconfig/modules/btrfs.modules
-rwxr-xr-x 1 root root 41 Dec 22 15:29 /etc/sysconfig/modules/btrfs.modules
[root@Perf-pxy-2 ~]#


5. 创建磁盘分区

建4个1G大小的分区
fdisk /dev/sda <<EOF
p
n

+1g
n

+1g
n

+1g
n

+1g
p
w
EOF
partprobe
[root@Perf-pxy-2 ~]# fdisk /dev/sda <<EOF
> p
> n
>
> +1g
> n
>
> +1g
> n
>
> +1g
> n
>
> +1g
> p
> w
> EOF

The number of cylinders for this disk is set to 8908.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)

Command (m for help):
Disk /dev/sda: 73.2 GB, 73274490880 bytes
255 heads, 63 sectors/track, 8908 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1925 15358140 83 Linux
/dev/sda3 1926 2945 8193150 83 Linux
/dev/sda4 2946 8908 47897797+ 5 Extended
/dev/sda5 2946 3455 4096543+ 82 Linux swap / Solaris

Command (m for help): First cylinder (3456-8908, default 3456): Using default value 3456
Last cylinder or +size or +sizeM or +sizeK (3456-8908, default 8908):
Command (m for help): First cylinder (3579-8908, default 3579): Using default value 3579
Last cylinder or +size or +sizeM or +sizeK (3579-8908, default 8908):
Command (m for help): First cylinder (3702-8908, default 3702): Using default value 3702
Last cylinder or +size or +sizeM or +sizeK (3702-8908, default 8908):
Command (m for help): First cylinder (3825-8908, default 3825): Using default value 3825
Last cylinder or +size or +sizeM or +sizeK (3825-8908, default 8908):
Command (m for help):
Disk /dev/sda: 73.2 GB, 73274490880 bytes
255 heads, 63 sectors/track, 8908 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1925 15358140 83 Linux
/dev/sda3 1926 2945 8193150 83 Linux
/dev/sda4 2946 8908 47897797+ 5 Extended
/dev/sda5 2946 3455 4096543+ 82 Linux swap / Solaris
/dev/sda6 3456 3578 987966 83 Linux
/dev/sda7 3579 3701 987966 83 Linux
/dev/sda8 3702 3824 987966 83 Linux
/dev/sda9 3825 3947 987966 83 Linux

Command (m for help): The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
[root@Perf-pxy-2 ~]# partprobe
[root@Perf-pxy-2 ~]#


6. 创建文件系统

mkfs.btrfs /dev/sda6
mkfs.btrfs /dev/sda7
mkfs.btrfs /dev/sda8
mkfs.btrfs /dev/sda9
btrfs-show
[root@Perf-pxy-2 ~]# mkfs.btrfs /dev/sda6
fs created label (null) on /dev/sda6
nodesize 4096 leafsize 4096 sectorsize 4096 size 964.81MB
Btrfs Btrfs v0.16
[root@Perf-pxy-2 ~]# mkfs.btrfs /dev/sda7
fs created label (null) on /dev/sda7
nodesize 4096 leafsize 4096 sectorsize 4096 size 964.81MB
Btrfs Btrfs v0.16
[root@Perf-pxy-2 ~]# mkfs.btrfs /dev/sda8
fs created label (null) on /dev/sda8
nodesize 4096 leafsize 4096 sectorsize 4096 size 964.81MB
Btrfs Btrfs v0.16
[root@Perf-pxy-2 ~]# mkfs.btrfs /dev/sda9
fs created label (null) on /dev/sda9
nodesize 4096 leafsize 4096 sectorsize 4096 size 964.81MB
Btrfs Btrfs v0.16
[root@Perf-pxy-2 ~]# btrfs-show
failed to read /dev/fd0u1120
failed to read /dev/fd0u830
failed to read /dev/fd0u720
failed to read /dev/fd0u1920
failed to read /dev/fd0u1743
failed to read /dev/fd0u1680
failed to read /dev/fd0
failed to read /dev/hda
Label: none uuid: 7f473f0f-e354-4e4b-b8d8-afd164c9aa36
Total devices 1 FS bytes used 40.00KB
devid 1 size 964.81MB used 132.38MB path /dev/sda8

Label: none uuid: 7042801b-28df-4620-83bb-5237f4fdeae4
Total devices 1 FS bytes used 40.00KB
devid 1 size 964.81MB used 132.38MB path /dev/sda7

Label: none uuid: 30cb5dcf-7fd0-4704-be8f-ea73dac61cd0
Total devices 1 FS bytes used 40.00KB
devid 1 size 964.81MB used 132.38MB path /dev/sda9

Label: none uuid: 80709a87-b5e2-475a-81af-6d94accd21c0
Total devices 1 FS bytes used 40.00KB
devid 1 size 964.81MB used 132.38MB path /dev/sda6

Btrfs Btrfs v0.16
[root@Perf-pxy-2 ~]#

挂载根卷
mkdir -p /mnt/btrfs-root
mount -t btrfs -o subvol=. /dev/sda6 /mnt/btrfs-root
ls -laR /mnt/btrfs-root/
mount -t btrfs
df -h /mnt/btrfs-root
[root@Perf-pxy-2 ~]# mkdir -p /mnt/btrfs-root
[root@Perf-pxy-2 ~]# mount -t btrfs -o subvol=. /dev/sda6 /mnt/btrfs-root
[root@Perf-pxy-2 ~]# ls -laR /mnt/btrfs-root/
/mnt/btrfs-root/:
total 9
dr-xr-xr-x 1 root root 0 Jan 1 1970 .
drwxr-xr-x 3 root root 4096 Dec 23 10:31 ..
dr-xr-xr-x 1 root root 0 Jan 1 1970 default

/mnt/btrfs-root/default:
total 1
dr-xr-xr-x 1 root root 0 Jan 1 1970 .
dr-xr-xr-x 1 root root 0 Jan 1 1970 ..
[root@Perf-pxy-2 ~]# mount -t btrfs
/dev/sda6 on /mnt/btrfs-root type btrfs (rw,subvol=.)
[root@Perf-pxy-2 ~]# df -h /mnt/btrfs-root
Filesystem Size Used Avail Use% Mounted on
/dev/sda6 965M 44K 965M 1% /mnt/btrfs-root
[root@Perf-pxy-2 ~]#
根卷下有一个默认的default子卷


7. 创建子卷

在根卷上建一个新的子卷
btrfsctl -s sv_test /mnt/btrfs-root
[root@Perf-pxy-2 ~]# btrfsctl -s sv_test /mnt/btrfs-root
operation complete
Btrfs Btrfs v0.16
[root@Perf-pxy-2 ~]#

挂载子卷
mkdir -p /mnt/btrfs-sv_test
mount -t btrfs -o subvol=sv_test /dev/sda6 /mnt/btrfs-sv_test
ls -laR /mnt/btrfs-sv_test/
mount -t btrfs
df -h /mnt/btrfs-*
[root@Perf-pxy-2 ~]# mkdir -p /mnt/btrfs-sv_test
[root@Perf-pxy-2 ~]# mount -t btrfs -o subvol=sv_test /dev/sda6 /mnt/btrfs-sv_test
[root@Perf-pxy-2 ~]# ls -laR /mnt/btrfs-sv_test/
/mnt/btrfs-sv_test/:
total 8
drwx------ 1 root root 0 Dec 23 10:33 .
drwxr-xr-x 4 root root 4096 Dec 23 10:33 ..
[root@Perf-pxy-2 ~]# mount -t btrfs
/dev/sda6 on /mnt/btrfs-root type btrfs (rw,subvol=.)
/dev/sda6 on /mnt/btrfs-sv_test type btrfs (rw,subvol=sv_test)
[root@Perf-pxy-2 ~]# df -h /mnt/btrfs-*
Filesystem Size Used Avail Use% Mounted on
/dev/sda6 965M 44K 965M 1% /mnt/btrfs-root
/dev/sda6 965M 44K 965M 1% /mnt/btrfs-sv_test
[root@Perf-pxy-2 ~]#

ls -laR /mnt/btrfs-root/
[root@Perf-pxy-2 ~]# ls -laR /mnt/btrfs-root/
/mnt/btrfs-root/:
total 9
dr-xr-xr-x 1 root root 0 Jan 1 1970 .
drwxr-xr-x 4 root root 4096 Dec 23 10:33 ..
dr-xr-xr-x 1 root root 0 Jan 1 1970 default
drwx------ 1 root root 0 Dec 23 10:33 sv_test

/mnt/btrfs-root/default:
total 1
dr-xr-xr-x 1 root root 0 Jan 1 1970 .
dr-xr-xr-x 1 root root 0 Jan 1 1970 ..

/mnt/btrfs-root/sv_test:
total 1
drwx------ 1 root root 0 Dec 23 10:33 .
dr-xr-xr-x 1 root root 0 Jan 1 1970 ..
[root@Perf-pxy-2 ~]#
根卷下自动创建了该子卷的目录

创建一个文件, 500兆
dd if=/dev/zero of=/mnt/btrfs-sv_test/file1 bs=1024 count=$((1024*500))
ls -l /mnt/btrfs-sv_test/
df -h /mnt/btrfs-sv_test/
[root@Perf-pxy-2 ~]# dd if=/dev/zero of=/mnt/btrfs-sv_test/file1 bs=1024 count=$((1024*500))
512000+0 records in
512000+0 records out
524288000 bytes (524 MB) copied, 9.58796 seconds, 54.7 MB/s
[root@Perf-pxy-2 ~]# ls -l /mnt/btrfs-sv_test/
total 410114
-rw-r--r-- 1 root root 524288000 Dec 23 10:35 file1
[root@Perf-pxy-2 ~]# df -h /mnt/btrfs-sv_test/
Filesystem Size Used Avail Use% Mounted on
/dev/sda6 965M 399M 567M 42% /mnt/btrfs-sv_test
[root@Perf-pxy-2 ~]# du -sh /mnt/btrfs-sv_test/
401M /mnt/btrfs-sv_test/
[root@Perf-pxy-2 ~]#
400M了, 过一分钟再查看
[root@Perf-pxy-2 ~]# df -h /mnt/btrfs-sv_test/
Filesystem Size Used Avail Use% Mounted on
/dev/sda6 965M 424M 542M 44% /mnt/btrfs-sv_test
[root@Perf-pxy-2 ~]#
越来越大
[root@Perf-pxy-2 ~]# df -h /mnt/btrfs-sv_test/
Filesystem Size Used Avail Use% Mounted on
/dev/sda6 965M 501M 465M 52% /mnt/btrfs-sv_test
[root@Perf-pxy-2 ~]#


9. 创建快照

给子卷btrfs-sv_test创建一个快照
btrfsctl -s ss_of_sv_test /mnt/btrfs-sv_test/
ls -l /mnt/btrfs-root/
[root@Perf-pxy-2 ~]# btrfsctl -s ss_of_sv_test /mnt/btrfs-sv_test/
operation complete
Btrfs Btrfs v0.16
[root@Perf-pxy-2 ~]# ls -l /mnt/btrfs-root/
total 1
dr-xr-xr-x 1 root root 0 Jan 1 1970 default
drwx------ 1 root root 10 Dec 23 10:35 ss_of_sv_test
drwx------ 1 root root 10 Dec 23 10:35 sv_test
[root@Perf-pxy-2 ~]#
根卷下也新建了一个目录

挂载快照
mkdir -p /mnt/btrfs-ss_of_sv_test
mount -t btrfs -o subvol=ss_of_sv_test /dev/sda6 /mnt/btrfs-ss_of_sv_test
mount -t btrfs
df -h /mnt/btrfs-*
ls -l /mnt/btrfs-ss_of_sv_test/
[root@Perf-pxy-2 ~]# mkdir -p /mnt/btrfs-ss_of_sv_test
[root@Perf-pxy-2 ~]# mount -t btrfs -o subvol=ss_of_sv_test /dev/sda6 /mnt/btrfs-ss_of_sv_test
[root@Perf-pxy-2 ~]# mount -t btrfs
/dev/sda6 on /mnt/btrfs-root type btrfs (rw,subvol=.)
/dev/sda6 on /mnt/btrfs-sv_test type btrfs (rw,subvol=sv_test)
/dev/sda6 on /mnt/btrfs-ss_of_sv_test type btrfs (rw,subvol=ss_of_sv_test)
[root@Perf-pxy-2 ~]# df -h /mnt/btrfs-*
Filesystem Size Used Avail Use% Mounted on
/dev/sda6 965M 501M 465M 52% /mnt/btrfs-root
/dev/sda6 965M 501M 465M 52% /mnt/btrfs-ss_of_sv_test
/dev/sda6 965M 501M 465M 52% /mnt/btrfs-sv_test
[root@Perf-pxy-2 ~]# ls -l /mnt/btrfs-ss_of_sv_test/
total 512006
-rw-r--r-- 1 root root 524288000 Dec 23 10:35 file1
[root@Perf-pxy-2 ~]#
文件file1在快照中有

btrfs-show
[root@Perf-pxy-2 ~]# btrfs-show
failed to read /dev/fd0u1120
failed to read /dev/fd0u830
failed to read /dev/fd0u720
failed to read /dev/fd0u1920
failed to read /dev/fd0u1743
failed to read /dev/fd0u1680
failed to read /dev/fd0
failed to read /dev/hda
Label: none uuid: 7f473f0f-e354-4e4b-b8d8-afd164c9aa36
Total devices 1 FS bytes used 40.00KB
devid 1 size 964.81MB used 132.38MB path /dev/sda8

Label: none uuid: 7042801b-28df-4620-83bb-5237f4fdeae4
Total devices 1 FS bytes used 40.00KB
devid 1 size 964.81MB used 132.38MB path /dev/sda7

Label: none uuid: 30cb5dcf-7fd0-4704-be8f-ea73dac61cd0
Total devices 1 FS bytes used 40.00KB
devid 1 size 964.81MB used 132.38MB path /dev/sda9

Label: none uuid: 80709a87-b5e2-475a-81af-6d94accd21c0
Total devices 1 FS bytes used 500.64MB
devid 1 size 964.81MB used 903.88MB path /dev/sda6

Btrfs Btrfs v0.16
[root@Perf-pxy-2 ~]#

创建3个文件
dd if=/dev/urandom of=/mnt/btrfs-sv_test/file1 bs=1024 count=$((3*1024))
dd if=/dev/urandom of=/mnt/btrfs-sv_test/file2 bs=1024 count=$((2*1024))
dd if=/dev/urandom of=/mnt/btrfs-ss_of_sv_test/file3 bs=1024 count=$((1*1024))
df -h /mnt/btrfs-*
ls -l /mnt/btrfs-sv_test/
ls -l /mnt/btrfs-ss_of_sv_test/
[root@Perf-pxy-2 ~]# dd if=/dev/urandom of=/mnt/btrfs-sv_test/file1 bs=1024 count=$((3*1024))
3072+0 records in
3072+0 records out
3145728 bytes (3.1 MB) copied, 0.647297 seconds, 4.9 MB/s
[root@Perf-pxy-2 ~]# dd if=/dev/urandom of=/mnt/btrfs-sv_test/file2 bs=1024 count=$((2*1024))
2048+0 records in
2048+0 records out
2097152 bytes (2.1 MB) copied, 0.434674 seconds, 4.8 MB/s
[root@Perf-pxy-2 ~]# dd if=/dev/urandom of=/mnt/btrfs-ss_of_sv_test/file3 bs=1024 count=$((1*1024))
1024+0 records in
1024+0 records out
1048576 bytes (1.0 MB) copied, 0.219023 seconds, 4.8 MB/s
[root@Perf-pxy-2 ~]# df -h /mnt/btrfs-*
Filesystem Size Used Avail Use% Mounted on
/dev/sda6 965M 501M 465M 52% /mnt/btrfs-root
/dev/sda6 965M 501M 465M 52% /mnt/btrfs-ss_of_sv_test
/dev/sda6 965M 501M 465M 52% /mnt/btrfs-sv_test
[root@Perf-pxy-2 ~]# ls -l /mnt/btrfs-sv_test/
total 5138
-rw-r--r-- 1 root root 3145728 Dec 24 03:15 file1
-rw-r--r-- 1 root root 2097152 Dec 24 03:16 file2
[root@Perf-pxy-2 ~]# ls -l /mnt/btrfs-ss_of_sv_test/
total 513036
-rw-r--r-- 1 root root 524288000 Dec 23 10:35 file1
-rw-r--r-- 1 root root 1048576 Dec 24 03:16 file3
[root@Perf-pxy-2 ~]#
快照是可写的


10. 删除快照

快照目录删不掉, 只能删除目录下的所有文件, 释放空间
df -h /mnt/btrfs-*
rm -rf /mnt/btrfs-ss_of_sv_test/
ls -la /mnt/btrfs-ss_of_sv_test/
umount /mnt/btrfs-ss_of_sv_test/
rm -rf /mnt/btrfs-ss_of_sv_test/
ls -la /mnt/btrfs-root/
rmdir /mnt/btrfs-root/ss_of_sv_test
ls -la /mnt/btrfs-root/
df -h /mnt/btrfs-*
[root@Perf-pxy-2 ~]# df -h /mnt/btrfs-*
Filesystem Size Used Avail Use% Mounted on
/dev/sda6 965M 507M 459M 53% /mnt/btrfs-root
/dev/sda6 965M 507M 459M 53% /mnt/btrfs-ss_of_sv_test
/dev/sda6 965M 507M 459M 53% /mnt/btrfs-sv_test
[root@Perf-pxy-2 ~]# rm -rf /mnt/btrfs-ss_of_sv_test/
rm: cannot remove directory `/mnt/btrfs-ss_of_sv_test/': Device or resource busy
[root@Perf-pxy-2 ~]# ls -la /mnt/btrfs-ss_of_sv_test/
total 8
drwx------ 1 root root 0 Dec 24 03:18 .
drwxr-xr-x 5 root root 4096 Dec 23 10:41 ..
[root@Perf-pxy-2 ~]# umount /mnt/btrfs-ss_of_sv_test/
[root@Perf-pxy-2 ~]# rm -rf /mnt/btrfs-ss_of_sv_test/
[root@Perf-pxy-2 ~]# ls -la /mnt/btrfs-root/
total 9
dr-xr-xr-x 1 root root 0 Jan 1 1970 .
drwxr-xr-x 4 root root 4096 Dec 24 03:19 ..
dr-xr-xr-x 1 root root 0 Jan 1 1970 default
drwx------ 1 root root 0 Dec 24 03:18 ss_of_sv_test
drwx------ 1 root root 20 Dec 24 03:16 sv_test
[root@Perf-pxy-2 ~]# rmdir /mnt/btrfs-root/ss_of_sv_test
rmdir: /mnt/btrfs-root/ss_of_sv_test: Operation not permitted
[root@Perf-pxy-2 ~]# ls -la /mnt/btrfs-root/
total 9
dr-xr-xr-x 1 root root 0 Jan 1 1970 .
drwxr-xr-x 4 root root 4096 Dec 24 03:19 ..
dr-xr-xr-x 1 root root 0 Jan 1 1970 default
drwx------ 1 root root 0 Dec 24 03:18 ss_of_sv_test
drwx------ 1 root root 20 Dec 24 03:16 sv_test
[root@Perf-pxy-2 ~]# df -h /mnt/btrfs-*
Filesystem Size Used Avail Use% Mounted on
/dev/sda6 965M 5.1M 960M 1% /mnt/btrfs-root
/dev/sda6 965M 5.1M 960M 1% /mnt/btrfs-sv_test
[root@Perf-pxy-2 ~]#

删除子卷也是一样的, 删除那个都行


11. 多设备
添加删除设备有问题, 不好用


12. 空间满ENOSPC
磁盘空间满了可能造成系统崩溃


13. 其它文件系统
nilfs [http://www.nilfs.org]:
持续快照(continuous snapshotting), 任何修改都记录检查点, 删除快照或检查点会导致产生新的检查点, 占用空间巨大

tux3 [http://tux3.org]:
太新了, 目前还是fuse的

hammer[http://www.dragonflybsd.org/hammer/]:
DragonFly BSD上用的

zfs on fuse [http://www.wizy.org/wiki/ZFS_on_FUSE]:
FUSE据说很慢


外部链接:

btrfs
Btrfs(wikipedia)
Btrfs trees for linux-next
Btrfs mainline plans
Kernel Log: Ext4 completes development phase as interim step to btrfs
Ext4 Advances As Interim Step To Btrfs
List of file systems
Comparison_of file systems
Emerging Filesystems
On File Systems
More Linux File Systems






Xie Wen (谢文)
Network & Operations,
Multimedia Applications & Services (MDB) MOTOROLA Inc.
NO.104 mail box,
8th floor, Motorola Tower,
No. 1 Wang Jing East Road, Chao Yang District,
Beijing 100102 P. R. China
e-mail wenxie at motorola.com



=====
updated on Jan. 17, 2009: btrfs v0.18版发布了





-fin-

Thursday, December 18, 2008

recovery window - RMAN的恢复窗口

---------- Forwarded message ----------
From: XIE WEN-MFK346 <wenxie at motorola.com>
Date: Thu, Dec 18, 2008 at 18:06
Subject: recovery window
To: wen xie <xiewenxiewen at googlemail.com>



recovery window

4.
60. You defined the Recovery Manager (RMAN) retention policy to recovery window
of 7 days by executing the following command:
RMAN> CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
When a backup is performed, what would be the status of this backup after seven days?
A. The backup would be marked as invalid.
(B). The backup would be marked as obsolete.
C. The backup would be removed from the media.
D. The backup would be removed from the RMAN repository.

12.
179. The backup retention policy is configured as RECOVERY WINDOW 2.
You executed the following command in Recovery Manager (RMAN) against your database:
RMAN> REPORT OBSOLETE;
What would you see in the output?
A. a list of all those files that have been deleted in the last two days
B. a list of all those files that have been recovered within the last two days
C. a list of all the expired backups and copies
(D). a list of backups and copies that are outside the range covered by the current retention policy

还是1z0-043的考题, 在下认为出的不好, 没有对的
第1题后来没再做备份, 所以第一个备份肯定留着, 不会被标记为过期
应该是, 恢复窗口外(<=(今天-恢复窗口))保留最新一个, 窗口内(>(今天-恢复窗口))都保留
第2题D说的不严谨, 但是唯一接近正确的

测试如下:


1. 设置恢复窗口, 创建数据库备份

sqlplus -s /nolog <<EOF
conn / as sysdba
show parameter control_file_record_keep_time
exit
EOF
[oracle@Perf-pxy-2 ~]$ sqlplus -s /nolog <<EOF
> conn / as sysdba
> show parameter control_file_record_keep_time
> exit
> EOF

NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
control_file_record_keep_time integer 30
[oracle@Perf-pxy-2 ~]$

恢复窗口设置为7天
rman target /
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
show all;
RMAN> CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
new RMAN configuration parameters:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
new RMAN configuration parameters are successfully stored

RMAN> show all;

RMAN configuration parameters are:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
CONFIGURE BACKUP OPTIMIZATION OFF; # default
CONFIGURE DEFAULT DEVICE TYPE TO DISK; # default
CONFIGURE CONTROLFILE AUTOBACKUP OFF; # default
CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO '%F'; # default
CONFIGURE DEVICE TYPE DISK PARALLELISM 1 BACKUP TYPE TO BACKUPSET; # default
CONFIGURE DATAFILE BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE ARCHIVELOG BACKUP COPIES FOR DEVICE TYPE DISK TO 1; # default
CONFIGURE MAXSETSIZE TO UNLIMITED; # default
CONFIGURE ENCRYPTION FOR DATABASE OFF; # default
CONFIGURE ENCRYPTION ALGORITHM 'AES128'; # default
CONFIGURE ARCHIVELOG DELETION POLICY TO NONE; # default
CONFIGURE SNAPSHOT CONTROLFILE NAME TO '/home/oracle/app/oracle/product/10.2/dbs/snapcf_s10.f'; # default

RMAN>

备份数据库
backup device type disk format '/home/oracle/backup/s10/rman/db_%d_%I_%T_%s_%p_%U' database;
RMAN> backup device type disk format '/home/oracle/backup/s10/rman/db_%d_%I_%T_%s_%p_%U' database;

Starting backup at 2008-12-18 08:21:00
allocated channel: ORA_DISK_1
channel ORA_DISK_1: sid=1632 devtype=DISK
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
input datafile fno=00001 name=/home/oracle/app/oracle/oradata/s10/system01.dbf
input datafile fno=00002 name=/home/oracle/app/oracle/oradata/s10/undotbs01.dbf
input datafile fno=00003 name=/home/oracle/app/oracle/oradata/s10/sysaux01.dbf
input datafile fno=00004 name=/home/oracle/app/oracle/oradata/s10/users01.dbf
channel ORA_DISK_1: starting piece 1 at 2008-12-18 08:21:01
channel ORA_DISK_1: finished piece 1 at 2008-12-18 08:21:26
piece handle=/home/oracle/backup/s10/rman/db_S10_1127563272_20081218_1_1_01k2i1jd_1_1 tag=TAG20081218T082101 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:25
channel ORA_DISK_1: starting full datafile backupset
channel ORA_DISK_1: specifying datafile(s) in backupset
including current control file in backupset
including current SPFILE in backupset
channel ORA_DISK_1: starting piece 1 at 2008-12-18 08:21:28
channel ORA_DISK_1: finished piece 1 at 2008-12-18 08:21:29
piece handle=/home/oracle/backup/s10/rman/db_S10_1127563272_20081218_2_1_02k2i1k6_1_1 tag=TAG20081218T082101 comment=NONE
channel ORA_DISK_1: backup set complete, elapsed time: 00:00:03
Finished backup at 2008-12-18 08:21:29

RMAN>

备份是18号的
list backup summary;
report obsolete;
RMAN> list backup summary;


List of Backups
===============
Key TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag
------- -- -- - ----------- ------------------- ------- ------- ---------- ---
1 B F A DISK 2008-12-18 08:21:21 1 1 NO TAG20081218T082101
2 B F A DISK 2008-12-18 08:21:28 1 1 NO TAG20081218T082101

RMAN> report obsolete;

RMAN retention policy will be applied to the command
RMAN retention policy is set to recovery window of 7 days
no obsolete backups found

RMAN>


2. 修改系统时间到7天后(25号), 查看备份状态

停数据库,系统时间修改为7天后,重启数据库
service ntpd stop
date && date $( date '+%m%d%H%M' --date='7 days' )
[root@Perf-pxy-2 ~]# service ntpd stop
Shutting down ntpd: [ OK ]
[root@Perf-pxy-2 ~]# date && date $( date '+%m%d%H%M' --date='7 days' )
Thu Dec 18 08:27:34 GMT 2008
Thu Dec 25 08:27:00 GMT 2008
[root@Perf-pxy-2 ~]#

查看备份状态
report obsolete;
RMAN> report obsolete;

using target database control file instead of recovery catalog
RMAN retention policy will be applied to the command
RMAN retention policy is set to recovery window of 7 days
Report of obsolete backups and copies
Type Key Completion Time Filename/Handle
-------------------- ------ ------------------ --------------------
Archive Log 1 2008-12-18 07:49:10 /home/oracle/app/oracle/oradata/s10/archive/1_5_673773960.arc
Archive Log 2 2008-12-18 08:18:31 /home/oracle/app/oracle/oradata/s10/archive/1_6_673773960.arc

RMAN>
没有过期


3. 改成10天后(28号), 再查看备份状态

date && date $( date '+%m%d%H%M' --date='3 days' )
[root@Perf-pxy-2 ~]# date && date $( date '+%m%d%H%M' --date='3 days' )
Thu Dec 25 08:38:36 GMT 2008
Sun Dec 28 08:38:00 GMT 2008
[root@Perf-pxy-2 ~]#

RMAN> report obsolete;

using target database control file instead of recovery catalog
RMAN retention policy will be applied to the command
RMAN retention policy is set to recovery window of 7 days
Report of obsolete backups and copies
Type Key Completion Time Filename/Handle
-------------------- ------ ------------------ --------------------
Archive Log 1 2008-12-18 07:49:10 /home/oracle/app/oracle/oradata/s10/archive/1_5_673773960.arc
Archive Log 2 2008-12-18 08:18:31 /home/oracle/app/oracle/oradata/s10/archive/1_6_673773960.arc

RMAN>
同样没有过期, 证明第1题是错的


4. 修改系统时间, 创建19,25,28号的备份

过程略

date $( date '+%m%d%H%M' --date='10 days ago' )
date $( date '+%m%d%H%M' --date='1 day' )
backup device type disk format '/home/oracle/backup/s10/rman/db_%d_%I_%T_%s_%p_%U' database;
date $( date '+%m%d%H%M' --date='6 day' )
backup device type disk format '/home/oracle/backup/s10/rman/db_%d_%I_%T_%s_%p_%U' database;
date $( date '+%m%d%H%M' --date='3 day' )
backup device type disk format '/home/oracle/backup/s10/rman/db_%d_%I_%T_%s_%p_%U' database;


5. 查看备份状态

现在是28号, 恢复窗口是7天
date
[root@Perf-pxy-2 ~]# date
Sun Dec 28 08:55:48 GMT 2008
[root@Perf-pxy-2 ~]#

显示过期状态的备份
list backup summary;
show retention policy;
report obsolete;
RMAN> list backup summary;


List of Backups
===============
Key TY LV S Device Type Completion Time #Pieces #Copies Compressed Tag
------- -- -- - ----------- ------------------- ------- ------- ---------- ---
1 B F A DISK 2008-12-18 08:21:21 1 1 NO TAG20081218T082101
2 B F A DISK 2008-12-18 08:21:28 1 1 NO TAG20081218T082101
3 B F A DISK 2008-12-19 08:53:36 1 1 NO TAG20081219T085317
4 B F A DISK 2008-12-19 08:53:44 1 1 NO TAG20081219T085317
5 B F A DISK 2008-12-25 08:54:43 1 1 NO TAG20081225T085425
6 B F A DISK 2008-12-25 08:54:52 1 1 NO TAG20081225T085425
7 B F A DISK 2008-12-28 08:55:44 1 1 NO TAG20081228T085526
8 B F A DISK 2008-12-28 08:55:52 1 1 NO TAG20081228T085526

RMAN> show retention policy;

RMAN configuration parameters are:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;

RMAN> report obsolete;

RMAN retention policy will be applied to the command
RMAN retention policy is set to recovery window of 7 days
Report of obsolete backups and copies
Type Key Completion Time Filename/Handle
-------------------- ------ ------------------ --------------------
Archive Log 1 2008-12-18 07:49:10 /home/oracle/app/oracle/oradata/s10/archive/1_5_673773960.arc
Archive Log 2 2008-12-18 08:18:31 /home/oracle/app/oracle/oradata/s10/archive/1_6_673773960.arc
Backup Set 1 2008-12-18 08:21:20
Backup Piece 1 2008-12-18 08:21:20 /home/oracle/backup/s10/rman/db_S10_1127563272_20081218_1_1_01k2i1jd_1_1
Backup Set 2 2008-12-18 08:21:28
Backup Piece 2 2008-12-18 08:21:28 /home/oracle/backup/s10/rman/db_S10_1127563272_20081218_2_1_02k2i1k6_1_1

RMAN>
18号的过期了, 因为28号的7天前是21号, 窗口内的25,28号的都保留, 窗口外保留最新一个,是19号的

显示恢复窗口是9天的过期的备份
report obsolete recovery window of 9 days;
RMAN> report obsolete recovery window of 9 days;

Report of obsolete backups and copies
Type Key Completion Time Filename/Handle
-------------------- ------ ------------------ --------------------
Archive Log 1 2008-12-18 07:49:10 /home/oracle/app/oracle/oradata/s10/archive/1_5_673773960.arc
Archive Log 2 2008-12-18 08:18:31 /home/oracle/app/oracle/oradata/s10/archive/1_6_673773960.arc
Backup Set 1 2008-12-18 08:21:20
Backup Piece 1 2008-12-18 08:21:20 /home/oracle/backup/s10/rman/db_S10_1127563272_20081218_1_1_01k2i1jd_1_1
Backup Set 2 2008-12-18 08:21:28
Backup Piece 2 2008-12-18 08:21:28 /home/oracle/backup/s10/rman/db_S10_1127563272_20081218_2_1_02k2i1k6_1_1

RMAN>
9天前是19号,所以19号以前是过期的

恢复窗口为10天
report obsolete recovery window of 10 days;
RMAN> report obsolete recovery window of 10 days;

Report of obsolete backups and copies
Type Key Completion Time Filename/Handle
-------------------- ------ ------------------ --------------------
Archive Log 1 2008-12-18 07:49:10 /home/oracle/app/oracle/oradata/s10/archive/1_5_673773960.arc
Archive Log 2 2008-12-18 08:18:31 /home/oracle/app/oracle/oradata/s10/archive/1_6_673773960.arc

RMAN>
10天前是18号,所以18号的留着,18号后的也留着, 没有过期的

恢复窗口为3,2,1,0天
report obsolete recovery window of 3 days;
RMAN> report obsolete recovery window of 3 days;

Report of obsolete backups and copies
Type Key Completion Time Filename/Handle
-------------------- ------ ------------------ --------------------
Archive Log 1 2008-12-18 07:49:10 /home/oracle/app/oracle/oradata/s10/archive/1_5_673773960.arc
Archive Log 2 2008-12-18 08:18:31 /home/oracle/app/oracle/oradata/s10/archive/1_6_673773960.arc
Backup Set 1 2008-12-18 08:21:20
Backup Piece 1 2008-12-18 08:21:20 /home/oracle/backup/s10/rman/db_S10_1127563272_20081218_1_1_01k2i1jd_1_1
Backup Set 2 2008-12-18 08:21:28
Backup Piece 2 2008-12-18 08:21:28 /home/oracle/backup/s10/rman/db_S10_1127563272_20081218_2_1_02k2i1k6_1_1
Backup Set 3 2008-12-19 08:53:36
Backup Piece 3 2008-12-19 08:53:36 /home/oracle/backup/s10/rman/db_S10_1127563272_20081219_3_1_03k2knru_1_1
Backup Set 4 2008-12-19 08:53:44
Backup Piece 4 2008-12-19 08:53:44 /home/oracle/backup/s10/rman/db_S10_1127563272_20081219_4_1_04k2knsn_1_1

RMAN>
RMAN> report obsolete recovery window of 2 days;

Report of obsolete backups and copies
Type Key Completion Time Filename/Handle
-------------------- ------ ------------------ --------------------
Archive Log 1 2008-12-18 07:49:10 /home/oracle/app/oracle/oradata/s10/archive/1_5_673773960.arc
Archive Log 2 2008-12-18 08:18:31 /home/oracle/app/oracle/oradata/s10/archive/1_6_673773960.arc
Backup Set 1 2008-12-18 08:21:20
Backup Piece 1 2008-12-18 08:21:20 /home/oracle/backup/s10/rman/db_S10_1127563272_20081218_1_1_01k2i1jd_1_1
Backup Set 2 2008-12-18 08:21:28
Backup Piece 2 2008-12-18 08:21:28 /home/oracle/backup/s10/rman/db_S10_1127563272_20081218_2_1_02k2i1k6_1_1
Backup Set 3 2008-12-19 08:53:36
Backup Piece 3 2008-12-19 08:53:36 /home/oracle/backup/s10/rman/db_S10_1127563272_20081219_3_1_03k2knru_1_1
Backup Set 4 2008-12-19 08:53:44
Backup Piece 4 2008-12-19 08:53:44 /home/oracle/backup/s10/rman/db_S10_1127563272_20081219_4_1_04k2knsn_1_1

RMAN> report obsolete recovery window of 1 days;

Report of obsolete backups and copies
Type Key Completion Time Filename/Handle
-------------------- ------ ------------------ --------------------
Archive Log 1 2008-12-18 07:49:10 /home/oracle/app/oracle/oradata/s10/archive/1_5_673773960.arc
Archive Log 2 2008-12-18 08:18:31 /home/oracle/app/oracle/oradata/s10/archive/1_6_673773960.arc
Backup Set 1 2008-12-18 08:21:20
Backup Piece 1 2008-12-18 08:21:20 /home/oracle/backup/s10/rman/db_S10_1127563272_20081218_1_1_01k2i1jd_1_1
Backup Set 2 2008-12-18 08:21:28
Backup Piece 2 2008-12-18 08:21:28 /home/oracle/backup/s10/rman/db_S10_1127563272_20081218_2_1_02k2i1k6_1_1
Backup Set 3 2008-12-19 08:53:36
Backup Piece 3 2008-12-19 08:53:36 /home/oracle/backup/s10/rman/db_S10_1127563272_20081219_3_1_03k2knru_1_1
Backup Set 4 2008-12-19 08:53:44
Backup Piece 4 2008-12-19 08:53:44 /home/oracle/backup/s10/rman/db_S10_1127563272_20081219_4_1_04k2knsn_1_1

RMAN> report obsolete recovery window of 0 days;

Report of obsolete backups and copies
Type Key Completion Time Filename/Handle
-------------------- ------ ------------------ --------------------
Archive Log 1 2008-12-18 07:49:10 /home/oracle/app/oracle/oradata/s10/archive/1_5_673773960.arc
Archive Log 2 2008-12-18 08:18:31 /home/oracle/app/oracle/oradata/s10/archive/1_6_673773960.arc
Backup Set 1 2008-12-18 08:21:20
Backup Piece 1 2008-12-18 08:21:20 /home/oracle/backup/s10/rman/db_S10_1127563272_20081218_1_1_01k2i1jd_1_1
Backup Set 2 2008-12-18 08:21:28
Backup Piece 2 2008-12-18 08:21:28 /home/oracle/backup/s10/rman/db_S10_1127563272_20081218_2_1_02k2i1k6_1_1
Backup Set 3 2008-12-19 08:53:36
Backup Piece 3 2008-12-19 08:53:36 /home/oracle/backup/s10/rman/db_S10_1127563272_20081219_3_1_03k2knru_1_1
Backup Set 4 2008-12-19 08:53:44
Backup Piece 4 2008-12-19 08:53:44 /home/oracle/backup/s10/rman/db_S10_1127563272_20081219_4_1_04k2knsn_1_1
Backup Set 5 2008-12-25 08:54:43
Backup Piece 5 2008-12-25 08:54:43 /home/oracle/backup/s10/rman/db_S10_1127563272_20081225_5_1_05k34i61_1_1
Backup Set 6 2008-12-25 08:54:52
Backup Piece 6 2008-12-25 08:54:52 /home/oracle/backup/s10/rman/db_S10_1127563272_20081225_6_1_06k34i6r_1_1

RMAN>


6. 恢复系统时间, 恢复保留策略

configure retention policy clear;
RMAN> configure retention policy clear;

old RMAN configuration parameters:
CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS;
RMAN configuration parameters are successfully reset to default value

RMAN>

date && date $( date '+%m%d%H%M' --date='10 days ago' )
[root@Perf-pxy-2 ~]# date && date $( date '+%m%d%H%M' --date='10 days ago' )
Sun Dec 28 09:49:31 GMT 2008
Thu Dec 18 09:49:00 GMT 2008
[root@Perf-pxy-2 ~]#





外部链接:

How does REPORT NEED BACKUP RECOVER WINDOW work ?
Delete Obsolete Does Not Delete Obsolete Backups
Rman backup retention policy
Frequently asked questions on Rman backup retention policy
recovery window (这上举的例子好像不对, 实际好像不计算到小时, 只考虑到天数)
Recovery Window
Recovery Window-Based Backup Retention Policy





Xie Wen (谢文)
Network & Operations,
Multimedia Applications & Services (MDB) MOTOROLA Inc.
NO.104 mail box,
8th floor, Motorola Tower,
No. 1 Wang Jing East Road, Chao Yang District,
Beijing 100102 P. R. China
e-mail wenxie at motorola.com


-fin-

Tuesday, December 16, 2008

loading and unloading data using external table - 使用外部表装载和卸载数据

---------- Forwarded message ----------
From: wen xie
Date: Tue, Dec 16, 2008 at 19:14
Subject: Fwd: loading and unloading data using external table
To: xiewenxiewen at googlemail.com




---------- Forwarded message ----------
From: XIE WEN-MFK346
Date: Tue, Dec 16, 2008 at 18:50
Subject: loading and unloading data using external table
To: wen xie




loading and unloading data using external table


10g外部表提供了将数据导出的功能

1. 建目录, 授权

conn / as sysdba
create or replace directory dp_dir as '/home/oracle/temp';
grant read,write on directory dp_dir to a;
grant read,write on directory dp_dir to b;
SQL> conn / as sysdba
Connected.
SQL> create or replace directory dp_dir as '/home/oracle/temp';

Directory created.

SQL> grant read,write on directory dp_dir to a;

Grant succeeded.

SQL> grant read,write on directory dp_dir to b;

Grant succeeded.

SQL>


2. 建测试表

conn a/a
drop table t;
create table t as select * from all_objects;
select count(*) from t;
SQL> conn a/a
Connected.
SQL> drop table t;
drop table t
*
ERROR at line 1:
ORA-00942: table or view does not exist


SQL> create table t as select * from all_objects;

Table created.

SQL> select count(*) from t;

COUNT(*)
----------
9447

SQL>


3. 导出到外部表

建立外部表, 用oracle_datapump方式导出

drop table ext_t;
create table ext_t
organization external (
type oracle_datapump
default directory dp_dir
access parameters (nologfile)
location ('ext_t.dmp')
)
reject limit unlimited
as
select * from t
/
select count(*) from ext_t;
SQL> drop table ext_t;
drop table ext_t
*
ERROR at line 1:
ORA-00942: table or view does not exist


SQL> create table ext_t
organization external (
type oracle_datapump
default directory dp_dir
access parameters (nologfile)
location ('ext_t.dmp')
)
reject limit unlimited
as
select * from t
/
2 3 4 5 6 7 8 9 10 11
Table created.

SQL> select count(*) from ext_t;

COUNT(*)
----------
9447

SQL>

生成了ext_t.dmp文件
!ls -lrt ~/temp/*.dmp
SQL> !ls -lrt ~/temp/*.dmp
-rw-r----- 1 oracle oinstall 872448 Dec 16 09:57 /home/oracle/temp/ext_t.dmp

SQL>


4. 取得表结构

下一步建表用


conn a/a
set long 4000 pages 9999 line 140
select dbms_metadata.get_ddl('TABLE','EXT_T') from dual;
SQL> conn a/a
Connected.
SQL> set long 4000 pages 9999 line 140
SQL> select dbms_metadata.get_ddl('TABLE',
'EXT_T') from dual;

DBMS_METADATA.GET_DDL('TABLE','EXT_T')
--------------------------------------------------------------------------------

CREATE TABLE "A"."EXT_T"
( "OWNER" VARCHAR2(30),
"OBJECT_NAME" VARCHAR2(30),
"SUBOBJECT_NAME" VARCHAR2(30),
"OBJECT_ID" NUMBER,
"DATA_OBJECT_ID" NUMBER,
"OBJECT_TYPE" VARCHAR2(19),
"CREATED" DATE,
"LAST_DDL_TIME" DATE,
"TIMESTAMP" VARCHAR2(19),
"STATUS" VARCHAR2(7),
"TEMPORARY" VARCHAR2(1),
"GENERATED" VARCHAR2(1),
"SECONDARY" VARCHAR2(1)
)
ORGANIZATION EXTERNAL
( TYPE ORACLE_DATAPUMP
DEFAULT DIRECTORY "DP_DIR"
ACCESS PARAMETERS
( nologfile )
LOCATION
( 'ext_t.dmp'
)
)
REJECT LIMIT UNLIMITED



SQL>


conn b/b
desc all_objects
SQL> conn b/b
Connected.
SQL> desc all_objects
Name Null? Type
------------------------------
----------- -------- ----------------------------
OWNER NOT NULL VARCHAR2(30)
OBJECT_NAME NOT NULL VARCHAR2(30)
SUBOBJECT_NAME VARCHAR2(30)
OBJECT_ID NOT NULL NUMBER
DATA_OBJECT_ID NUMBER
OBJECT_TYPE VARCHAR2(19)
CREATED NOT NULL DATE
LAST_DDL_TIME NOT NULL DATE
TIMESTAMP VARCHAR2(19)
STATUS VARCHAR2(7)
TEMPORARY VARCHAR2(1)
GENERATED VARCHAR2(1)
SECONDARY VARCHAR2(1)

SQL>


5. 建外部表, 导入数据

字段名和顺序要跟导出表一致


drop table ext_t1;
create table ext_t1 (
OWNER VARCHAR2(30),
OBJECT_NAME VARCHAR2(30),
SUBOBJECT_NAME VARCHAR2(30),
OBJECT_ID VARCHAR2(30),
DATA_OBJECT_ID VARCHAR2(30),
OBJECT_TYPE VARCHAR2(30),
CREATED VARCHAR2(30),
LAST_DDL_TIME VARCHAR2(30),
TIMESTAMP VARCHAR2(30),
STATUS VARCHAR2(30),
TEMPORARY VARCHAR2(30),
GENERATED VARCHAR2(30),
SECONDARY VARCHAR2(30)
)
organization external (
type oracle_datapump
default directory dp_dir
access parameters (nologfile)
location ('ext_t.dmp')
)
reject limit unlimited
/
select count(*) from ext_t1;
SQL> drop table ext_t1;
drop table ext_t1
*
ERROR at line 1:
ORA-00942: table or view does not exist


SQL> create table ext_t1 (
2 OWNER VARCHAR2(30),
3 OBJECT_NAME VARCHAR2(30),
4 SUBOBJECT_NAME VARCHAR2(30),
5 OBJECT_ID VARCHAR2(30),
6 DATA_OBJECT_ID VARCHAR2(30),
7 OBJECT_TYPE VARCHAR2(30),
8 CREATED VARCHAR2(30),
9 LAST_DDL_TIME VARCHAR2(30),
10 TIMESTAMP VARCHAR2(30),
11 STATUS VARCHAR2(30),
12 TEMPORARY VARCHAR2(30),
13 GENERATED VARCHAR2(30),
14 SECONDARY VARCHAR2(30)
15 )
16 organization external (
17 type oracle_datapump
18 default directory dp_dir
19 access parameters (nologfile)
20 location ('ext_t.dmp')
21 )
22 reject limit unlimited
23 /

Table created.

SQL> select count(*) from ext_t1;

COUNT(*)
----------
9447

SQL>


6. 不能用impdp导入

报错格式不一致


conn b/b
!impdp b/b directory=dp_dir dumpfile=ext_t.dmp tables=ext_t nologfile=y remap_schema=a:b
SQL> conn b/b
Connected.
SQL> !impdp b/b directory=dp_dir dumpfile=ext_t.dmp tables=ext_t nologfile=y remap_schema=a:b

Import: Release 10.2.0.4.0 - 64bit Production on Tuesday, 16 December, 2008 10:42:22

Copyright (c) 2003, 2007, Oracle. All rights reserved.

Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, Data Mining and Real Application Testing options
ORA-39001: invalid argument value
ORA-39000: bad dump file specification
ORA-31619: invalid dump file "/home/oracle/temp/ext_t.dmp"



SQL>

set serveroutput on size 1000000
exec system.show_dumpfile_info(p_dir=> 'dp_dir', p_file=> 'ext_t.dmp')
SQL> set serveroutput on size 1000000
SQL> exec system.show_dumpfile_info(p_
dir=> 'dp_dir', p_file=> 'ext_t.dmp')
----------------------------------------------------------------------------
Purpose..: Obtain details about export dumpfile. Version: 19-MAR-2008
Required.: RDBMS version: 10.2.0.1.0 or higher
. Export dumpfile version: 7.3.4.0.0 or higher
. Export Data Pump dumpfile version: 10.1.0.1.0 or higher
Usage....: execute show_dumfile_info('DIRECTORY', 'DUMPFILE');
Example..: exec show_dumfile_info('MY_DIR', 'expdp_s.dmp')
----------------------------------------------------------------------------
Filename.: ext_t.dmp
Directory: dp_dir
Disk Path: /home/oracle/temp
Filetype.: 1 (Export Data Pump dumpfile)
----------------------------------------------------------------------------
...File Version....: 1.1 (Oracle10g Release 2: 10.2.0.x)
...Master Present..: 1 (Yes)
...GUID............: 5E27FE1E5914DA98E040A8C0100B6117
...File Number.....: 1000001
...Characterset ID.: 873 (AL32UTF8)
...Creation Date...: Tue Dec 16 09:57:52 2008
...Flags...........: 10
...Job Name........:
...Platform........: x86_64/Linux 2.4.xx
...Language........: AL32UTF8
...Block size......: 4096
...Metadata Compres: 1 (Yes)
...Job Version.....: 10.02.00.03.00
...Max Items Code..: 15
----------------------------------------------------------------------------

PL/SQL procedure successfully completed.

SQL>





外部链接:

Unloading and Loading Data with the ORACLE_DATAPUMP Access Driver
Populating External TableGET_DUMPFILE_INFO Procedure





Xie Wen (谢文)
Network & Operations,
Multimedia Applications & Services (MDB) MOTOROLA Inc.
NO.104 mail box,
8th floor, Motorola Tower,
No. 1 Wang Jing East Road, Chao Yang District,
Beijing 100102 P. R. China
e-mail wenxie at motorola.com

Website Analytics

Followers