DBMS/MySQL2004. 10. 10. 18:28

1. 접속방법

# ./mysql -u root -p[pwd] [databae_name] 
# passwd: xxxxxx

2. 백업& 복구
2.1 특정 부분 데이터베이스만 백업&복구

백업
> ./mysql -uroot -p[비번] test > test_db.sql

복구(복구시 database를 만들고 복구해야함)
# mysql> create database test; 
# ./mysql -u root -p test < test_db.sql


2.2 전체 데이터베이스 백업

#mysqldump -u root -p 테이블명 -h 호스트> sql_backup_all.sql로 받았고...
#mysql -u roo -p 테이블명 -h 호스트< sql_backup_all.sql로 복구하려하고있습니다.

옵션 -u 사용자명
-p 패스워드
-h 호스트(localhost 일경우는 생략가능)

2.3 특정 테이블만 백업/복구
backup table table_name to '/path/bakcup';
restore table table_name from '/path/backup';



3. 데이터베이스 구동/종료/확인

./mysqladmin version
./bin/safe_mysqld& 시작
./mysqladmin -u root shutdown 종료
./mysqlshow
./mysqlshow mysql
./mysql -e "select host,db,user from db" mysql

이상 3번은 참고만 하세요. 


Posted by Jake Kim
OS/Server2004. 6. 24. 18:29

UPS 전원이 부족하면 자동으로 셧다운 되게 함

vi /etc/inittab

# When our UPS tells us power has failed, assume we have a few minutes
# of power left.  Schedule a shutdown for 2 minutes from now.
# This does, of course, assume you have powerd installed and your
# UPS connected and working correctly. 
pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down"
#전원이 부족하면 2분뒤에 시스템을 셧다운 시킴


# If power was restored before the shutdown kicked in, cancel it.
pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"
#2분안에 충전되면 셧다운 명령어 해지함
서자룡 리눅스8.0  461페이지

Posted by Jake Kim
OS/Server2004. 5. 21. 18:21

쿼터 3.x(레드헷 7.1 이상) 에서 확인한 방법임
설정한 환경 사항은

uname -a
Linux ns.my2pc.com 2.4.22-1.2174.nptlsmp #1 SMP Wed Feb 18 16:21:50 EST 2004 i686 i686 i386 GNU/Linux


레드헷 페도라 코어 1 버전임

[root@ns home]# cat /var/log/dmesg | grep quota
VFS: Disk quotas vdquot_6.5.1

vi /etc/fstab
LABEL=/                 /                       ext3      defaults             1 1
LABEL=/boot           /boot                 ext3      defaults             1 2
none                      /dev/pts             devpts  gid=5,mode=620  0 0
LABEL=/home         /home                ext3      defaults             1 2


대충 저리 비슷한 환경 이라고 보고
위에는 하드가 스카시라 저런 식으로 표시가 됩니다. 만약 ide 하드라면 hda1 hda2 과 같이 표시가 됩니다.

'/home' 파티션에 Quata를 설정하도록 하겠습니다. 아래과 같이 수정합니다.

LABEL=/home             /home             ext3    defaults,usrquota        1 2


usrquota 를 추가하였습니다.

[root@ns home]# mount -o remount /home
[root@ns home]# mount
/dev/cciss/c0d0p5 on / type ext3 (rw)
none on /proc type proc (rw)
none on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/cciss/c0d0p1 on /boot type ext3 (rw)
/dev/cciss/c0d0p7 on /home type ext3 (rw,usrquota)
none on /dev/shm type tmpfs (rw)
/dev/cciss/c0d0p3 on /usr type ext3 (rw)
/dev/cciss/c0d0p2 on /var type ext3 (rw)


mout 로 보면
/dev/cciss/c0d0p7 on /home type ext3 (rw,usrquota)
이렇게 되있음 쿼터 설정이 된 것입니다.

quota.user 파일 생성


사용자의 쿼터 정보를 담고 있는 파일인 quota.user  이게 자동으로 생기지 않으면 다음과 같은 명령을 실행합니다.

[root@ns home]# touch /home/quota.user
[root@ns home]# chmod 600 quota.user

[root@ns home]# convertquota -u /home/


만약 위의 명령어가 제대로 실행이 안 된다면

[root@ns home]# quotacheck -avugm


이 부분을 먼저 실행 하고 # convertquota -u /home/ 을 실행합니다.

그리고 ls -al 로 해서 살펴보면 aquota.user 이란 파일이 생성됐을 것입니다.

[root@ns home]# quotacheck -avug  
quotacheck: Cannot remount filesystem mounted on /home read-only so counted values might not be right.
Please stop all programs writing to filesystem or use -m flag to force checking.


위와 같이 에러가 발생하면 아래과 같이 입력합니다.

[root@ns home]# quotacheck -avugm
quotacheck: Scanning /dev/cciss/c0d0p7 [/home] done
quotacheck: Checked 4124 directories and 40103 files


 

[root@rootman /root]# quotacheck -a
Quota for users is enabled on mountpoint /home so quotacheck might damage the file.
Please turn quotas off or use -f to force checking.


위와 같은 경고 메시지를 만나면 당황하지 말고 quota를 잠시 중단하고 quotacheck를 한 후 다시 가동하면 된다.

[root@rootman /root]# quotaoff -a
[root@rootman /root]# quotacheck -a
[root@rootman /root]# quotaon -a


* 중요
만약 자신의 하드가 다른 물리적 파티션이거나 또는 다른 곳에서 마운트를 해왔다면 쿼터 적용이 안될 것이다. 그 부분을 위해 다른 곳도 쿼터에서 알수 있게 활성화를 시켜줘야 한다. 즉 /home 을 활성화 시킨다고 하면

quotaon -vaug /home


라고 하면

quotaon: using /home/aquota.user on /dev/hdb1: 장치나 자원 활성화


라는 문구가 뜰것이다 만약 이미 활성화가 되었다면

quotaon: using /home/aquota.user on /dev/hdb1: 장치나 자원이 동작 중


이런식의 문구가 뜰 것이다. 이 부분이 제대로 되어 있지않으면 사용자 정보가 제대로 반영이 안된다. 그러므로 아무리 쿼터를 적용할려고 하지만 적용이 안되는 불상사가 생겨 버린다.


* 계정 용량 할당 하기

[root@ns home]# edquota bresting

Disk quotas for user bresting (uid 510):
  Filesystem                   blocks       soft       hard     inodes     soft     hard
  /dev/cciss/c0d0p7           3126776          0          0        598        0        0


block(soft = 0, hard=0)
block 은 지금 사용하고 있는 총 용량
soft 는 용량의 제한을 둬서 그걸 넘으면 에러 메세지를 보냄
hard 는 그 용량 되면 더이상 못씀
inodes (soft =0,    hard=0)
이건 파일 게수를 뜻한 역시나 위와 같음

예를 들자면

Disk quotas for user bresting (uid 510):
  Filesystem                   blocks       soft       hard     inodes     soft     hard
  /dev/cciss/c0d0p7           50         51200          56320        10       1500     1550


50 메가 넘으면 경고 메세지 보냄
55 메가 넘으면 더이상 못씀
1500 게 파일 넘으면 경고 메세지
1550 게 파일 넘으면 더이상 못씀


* 유예 기간

[root@ns home]# edquota -t
Grace period before enforcing soft limits for users:
Time units may be: days, hours, minutes, or seconds
  Filesystem             Block grace period     Inode grace period
  /dev/cciss/c0d0p7                  7days                  7days



* 쿼터 설정 상태

[root@ns home]# repquota -a
*** Report for user quotas on device /dev/cciss/c0d0p7
Block grace time: 7days; Inode grace time: 7days
                        Block limits                File limits
User            used    soft    hard  grace    used  soft  hard  grace
----------------------------------------------------------------------
root      --    1216       0       0            141     0     0      
nobody    --   37960       0       0            825     0     0      
vpopmail  --    1688       0       0            181     0     0      
bresting  -- 3126776       0       0            598     0     0      
fellen    -- 26592228       0       0           1150     0     0      
mysql     --      20       0       0              5     0     0      
photo     --      24       0       0              6     0     0      
my2pc     --  332756       0       0           2394     0     0      
kang0927  -- 1410648       0       0           2713     0     0      
down      -- 6820940       0       0           1632     0     0      
jhs1013   -- 2646524       0       0           1644     0     0      
infoftp   -- 9556676       0       0           1213     0     0      
bibichu   -- 4675392       0       0           4668     0     0      
moriya    -- 9892968 9900000 9950000          13858     0     0      
heyworld  --      24       0       0              6     0     0      
heyoh     -- 8223824       0       0             75     0     0      
issey     -- 2285488       0       0          10063     0     0      
hayan     -- 1176884       0       0           1903     0     0      
club      --    5672       0       0            748     0     0      


쿼터 설정을 다른 사용자와 동일하게 설정 하기

edquota -p bresting bresting1 bresting2
bresting 의 환경을 bresting1 bresting2 에게 같이 적용

다중 사용자의 쿼터 적용
edquota -p bresting `awk -F: '$3 > 500 {print $1}' /etc/passwd`
awk 앞에는 숫자1 옆의 ` 그다음은 엔터 옆 ' ' passwd 는 숫자1 `

crontab -e
0 3 * * 0 /sbin/quotacheck -avugm

Posted by Jake Kim