2010年4月21日 星期三

VM中用Crontab排程跑 ntpdate校時筆記

環境:CentOS5.5
方式:/etc/cron.hourly/ntpdate.sh
記錄檔:/var/log/cron ,及 mail 到 root …一到兩小時記錄一次 (!?)


環境:SLES10
方式:crontab -e,跑 /root/stdtime.sh
crontab -e 裡的 job
有錯會寄信到root
記錄檔:/var/log/messages

環境:SLES10
方式:/etc/cron.hourly/stdtime.sh
/etc/cron.hourly/stdtime.sh 中自訂 echo訊息做記錄....
/usr/sbin/ntpdate clock.stdtime.gov.tw
echo "update time hourly log $(date) " /root/ntpdate-hourly.log
記錄檔:mail 到 root 及自定的log


http://figaro.neo-info.net/?p=666

Cron 執行時通常都會透過 Mail 告訴使用者該排程的執行狀態,若是不想收到這些訊息時,則可以透過下列方式來完成:
1. 以該使用者身份登入後,執行 crontab -e
2. 在所有排程的最上端輸入一行描述
MAILTO=""
這樣便不會再收到相關的郵件訊息了



Host Power Management Causes Problems with Guest Timekeeping (Windows Hosts)

2010年4月19日 星期一

[盜貼]文字介面、console的調整文章

http://cha.homeip.net/blog/archives/2006/06/_bootsplash_lin.html

用 bootsplash 妝點 Linux Console

  • 調整 Linux Console 解析度
  • 在 Linux Console 加入底圖
  • 自訂開機畫面


http://tetralet.luna.com.tw/index.php?op=ViewArticle&articleId=221&blogId=1
LilyTerm 新功能 - 支援 Window Title!


2010年4月16日 星期五

opensuse-tutorials

http://opensuse-tutorials.com/



Managing Nautilus from the keyboard
You don’t have to be slowed down by the mouse just because you are using a GUI. Nautilus has great keyboard shortcuts that will allow you to use it quickly and effectively.
Here is a quick table of the shortcut keys and their functionality
Key(s)Action
Searching
Start TypingSelect the matching name of a file or directory
CTRL+FSearch filenames and content of indexed files
CTRL+SSelects all files or directories matching a pattern
Display and Window Management
CTRL+NCreate a new Nautilus window
CTRL+WClose a Nautilus window
CTRL+SHIFT+WClose all Nautilus windows
CTRL+1View files in icon mode
CTRL+2View files in list mode
F9Toggle sidebar pane
File Management
CTRL+HShow hidden files
CTRL+SHIFT+NCreate a new folder
CTRL+T or DelDelete the file or directory and move to the trash
Shift+DelDelete the selected file or directory and skip the trash
F2Rename the selected file or directory
Alt+EnterView properties of the selected file or directory
Movement
CTRL+LMove into the location bar
Alt+HOMEGo to your $HOME folder
* or + or SHIFT+RArrowExpand Directory in list view
- or SHIFT+LArrowClose Directory in list view
ALT+LArrowBrowse through files and folders to the left
ALT+RArrowBrowse through files and folders to the right
ALT+UArrowMove to the parent folder one level above
ALT+DArrowOpen the selected file or folder
Accessibility
CTRL++Zoom in
CTRL+-Zoom out
CTRL+0Normal zoom

2010年2月5日 星期五

VMware server 防火牆要開的 port

主要目的為一台裝 VMware server (1.x版) 另一台client 只裝 console 連進去,分散 loading
預設 port 是 902

http://www.vmware.com/support/gsx3/doc/manage_portnum_gsx.html





http://www.electrictoolbox.com/vmware-server-console-connection-refused/



The error message we are looking at in this post is shown in the screenshot below, "Unable to connect to the remote host: Cannot connect to host x.y.z.a: Connection refused":
The reason for this error is likely to be caused by VMWare Server listening on a different port than the default (or that you got the IP address incorrect and are trying to connect to some other server!) By default, VMWare Server will listen on port 902, and VMWare Server Console will attempt to connect on port 902. However, it's possible that you or VMWare Server will have configured itself to listen on a different port number. This happened to me when I was setting up a VMWare Server and it offered to listen on port 904 instead.
To connect to VMWare Server using VMWare Server Console on a non-standard port, you simply add : followed by the port number after the "host name" setting as shown in the example screenshot below. In my example I have used the IP address 10.1.1.22 and the port 904, resulting in a host name of 10.1.1.22:904.



2010年2月2日 星期二

mysqldump 備份 MySQL[文摘]

mysqldump


FreeBSD下cron自动备份MySQL数据库的脚本
http://www.abc188.com/info/html/caozuoxitong/FreeBSD/20090513/127707.html

http://www.360doc.com/content/06/0829/09/11104_193248.shtml

在cpnael 利用 cron 定時 備份 mysql + html 文件
http://registerboy.pixnet.net/blog/post/22423003


http://forums.mysql.com/read.php?10,319298,319298#msg-319298

Crontab備份MySQL定時備份shell script自動刪除
http://www.dk101.com/Discuz/archiver/tid-161918.html

老鼠愛大米 2009-6-27 18:19

Crontab備份MySQL定時備份shell script自動刪除

MySQL 備份 shell script

這個是我日常用作備份 MySQL database 的 shell script,因為以前是直接將所有資料庫匯出成一個 sql 檔,當其中一個資料庫有問題時,因為沒問題的資料庫不想有改動,要復原資料很麻煩。今天改了一下,它會用 mysqldump 將所有資料庫匯出成獨立 sql 備份檔,然後用 gzip 壓縮成 .gz 檔案。程式會儲存 5 天的備份,當有新備份時,最舊的備份會自動刪除。

使用方法:
修改 db_user, db_passwd 及 db_host 修改成你的 mysql 登入資料,所使用的用戶權限需要與 mysql root 相同。backup_dir 修改成你希望儲存備份的目錄。

最後只要把程式加入 crontab 排程自動執行即可。[code]#!/bin/sh
# mysql_backup.sh: backup mysql databases and keep newest 5 days backup.
#
# Last updated: 20 March 2006
# ----------------------------------------------------------------------
# This is a free shell script under GNU GPL version 2.0 or above
# Copyright (C) 2006 Sam Tang
# Feedback/comment/suggestions : http://www.real-blog.com/
# ----------------------------------------------------------------------

# your mysql login information
# db_user is mysql username
# db_passwd is mysql password
# db_host is mysql host
# -----------------------------
db_user="root"
db_passwd=""
db_host="localhost"

# the directory for story your backup file.
backup_dir=""

# date format for backup file (dd-mm-yyyy)
time="$(date +"%d-%m-%Y")"

# mysql, mysqldump and some other bin's path
MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"
MKDIR="$(which mkdir)"
RM="$(which rm)"
MV="$(which mv)"
GZIP="$(which gzip)"

# check the directory for store backup is writeable
test ! -w $backup_dir && echo "Error: $backup_dir is un-writeable." && exit 0

# the directory for story the newest backup
test ! -d "$backup_dir/backup.0/" && $MKDIR "$backup_dir/backup.0/"

# get all databases
all_db="$($MYSQL -u $db_user -h $db_host -p$db_passwd -Bse 'show databases')"

for db in $all_db
do
        $MYSQLDUMP -u $db_user -h $db_host -p$db_passwd $db | $GZIP -9 > "$backup_dir/backup.0/$time.$db.gz"
done

# delete the oldest backup
test -d "$backup_dir/backup.5/" && $RM -rf "$backup_dir/backup.5"

# rotate backup directory
for int in 4 3 2 1 0
do
        if(test -d "$backup_dir"/backup."$int")
        then
                next_int=`expr $int + 1`
                $MV "$backup_dir"/backup."$int" "$backup_dir"/backup."$next_int"
        fi
done

exit 0;[/code]--------------------------------------------------
Crontab 備份www、mysql資料夾內容有問題
阿修 Ident: 75878664309b1e12165b 2008/11/18 9:23
請問一下~ 我想要排程備份apacher server的 mysql資料夾與WWW資料夾
但是使用crontab時發現~除了系統的的crontab(/etc/crontab)可以排程外。
在使用者環境下或是用SSH以root登入的crontaba -e所寫的都沒有執行
而且就算利用/etc/crontab來排程~排程備份出來的tar.gz是有問題的
我測試過腳本是沒有問題~~請問一下要如何解決呢?
排程語法:(在/etc/crontab 或是以管理員root或使用者身份進入crontab -e所寫的)
00 18 * * * root /usr/bin/backweb
腳本:/usr/bin/backweb (root.root 755)
ymd=`date +%Y%m%d `
tar cvzf /backup_daily/db/mysql_db_$ymd.tar.gz /var/lib/mysql
tar cvzf /backup_daily/web/web_web$ymd.tar.gz /var/www
tar cvzf /backup_daily/phpini/phpini$ymd.tar.gz /etc/php5/apache2
---------------------------------------------------------
cron 是一個服務(service)名稱
/etc/crontab 為其主要設定檔

當更改設定檔後,需要重新載入或重新啟動,使其立刻生效
# /etc/init.d/cron rload

# /etc/init.d/cron restart

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

直接備份 mysql 資料庫(非用 sql 語法導出)
這是最簡單也最快速的備份法
但缺點是需要先關閉 mysql 服務,再備份
否則備份出來的資料庫,很有可能是錯誤的,需要修復

因為表格仍在開啟中就備份,存回去時可能被程式認為是錯誤的
另也有可能備份那瞬間,網頁正在操作資料庫
比如論壇有人正在發文寫入資料庫或其它的
將那瞬間的狀態備份下來,存回去時當然就有錯誤了
所以備份前必須先關閉 mysql 服務

然而關閉 mysql 服務,網站就會停擺...
頁面上會出現資料庫錯誤,很難看

提供我的作法給你參考:
---------------------------------
1.先建立一個備份專用的網頁目錄,比如 /var/www2。內容只有一個 index.html,畫面是:資料庫備份中,或網站維護中,請瀏覽者稍待1~2分鐘...之類的,常逛網路,這種畫面你應該見過。

2.另外要有 404.php 這個檔,404 網頁找不到功能,需於 http.conf 中開啟。內容很簡單,強制導向到 index.html,也就是網站維護中的頁面。[code]// Location 強迫導向,僅能使用「絕對路徑」
header ("Location: http://yourdomain/index.html") ;
exit ;
?>[/code]---------------------------------------------------------------
3.備份前
mv /var/www /var/www3 #將原先目錄更名
mv /var/www2 /var/www #維護中頁面頂上去
這個是瞬間的,不到 0.5 秒

不管瀏覽者正在看什麼頁面,當他按下連結,因為目錄已經改變了,找不到檔案,便會得到 404 訊息。而 404 剛前面已經設定為強制導向到 index.htm 也就是:網站維護中的頁面。

4.接著關閉 mysql 服務,建議先等個 3秒,然後開始備份

/etc/init.d/mysqld stop
slee 3

5.備份完成後,照原來順序,還原回去
先啟動 msyqld,等個3~5秒,因為啟動需要時間
將 www 更名回 ww2,將 www3 更名回 www

不管如何,備份 mysql 是一定要停止服務的,除非你用 sql 語法導出或其它備援機制。

以上作法仍會使網站停擺,但是對外面的訪客來說,他們會看到網站維護中的頁面,並得知過 3分鐘後再來就可以看了,而不是資料庫錯誤的頁面。常逛網路,你應該也看過資料庫錯誤的頁面,會覺得說這個網站很不夠專業,且也不曉得啥時才會恢復。這之間的差別就是在這裡。

建議自動備份時間為當地時間凌晨 4~6 點,根據流量統計,這時段訪客人數最少,影響最小。
-----------------------------------------------
但是~我現在的狀況是~我要排程備份mysql與www這兩個資料夾~

在獨立執行腳本時可以執行備份動作~備份出來的db.tar.gz與web.tar.gz解壓縮後裡面是完整的內容。

但是放入排程執行後是有備份成功,但是出來的db.tar.gz與web.tar.gz內容有問題(解tar 出來後發現mysql只有部分資料庫,web.tar.gz則是沒有內容只有20bytes)

mysql資料夾權限/群組(mysql.mysql)而www資料夾(root.root)

PS:我在腳本前後有加上 /etc/init.d/apache2 stop與 /etc/init.d/apache2 start

設定/etc/crontab環境條件 nbuntu desktop 8.04 以root身份登入desktop環境

請問一下~有人可以解疑為何會這樣呢?感謝

backweb腳本:(/usr/bin/backweb)

ymd=`date +%Y%m%d `
/etc/init.d/mysql stop
/etc/init.d/apache2 stop
tar cvzf /backup_daily/db/mysql_db_$ymd.tar.gz /var/lib/mysql
tar cvzf /backup_daily/web/web_web$ymd.tar.gz /var/www
tar cvzf /backup_daily/phpini/phpini$ymd.tar.gz /etc/php5/apache2
/etc/init.d/apache2 start
/etc/init.d/mysql start
---------------------------------------------------------
我原先也是沒有停止apache與mysql就直接備份但視還是一樣的情況~腳本可以直接執行~

備份出來的tar.gz檔也正確~

但是~放到排程裡面備份出來的就是不行~

有tar.gz檔但內容不完全和沒有資料

我有嘗試將www資料內所有目錄檔案改成(root.root)使用者.群組 權限和mysql改成(root.mysql)

但是利用排程備份結果還是一樣,有排程備份到,但是內容資料還是和上面情況一樣是有問題的~
----------------------------------------------------
debug 偵錯
補抓執行中的訊息(包含錯誤訊息)存到 log 檔

用大於符號,將訊息重新導向存檔
$ 指令敘述 > /root/backup-log.txt 2>&1
老鼠愛大米 2009-6-27 18:50

Cron自動執行指令的備份mysql的問題

我以root身份執行crontab -e
程式碼:
cp -rf /var/mail /root/data_backup
tar -zcf /root/data_backup/home.tar.gz /home

這些指令很正常因為有部份指令我拿掉了。
有問題的指令是在cron下才會有問題,如果一般常在putty的視窗下執行是ok的~
我原本有幾行是在做mysqldump指令~備份資料庫
(以下代碼確定是一行無斷行)
程式碼:
mysqldump -uusername -ppasswd db > /root/data_backup/mysqldb/db.sql
我也試過把在上面的指令在putty上貼上以上指令執行是ok的
然後我也試過改成
程式碼:
/root/data_backup/mysqldb/mysqldb_backup.sh

而mysqldb_backup.sh檔案裡面有寫上面的mysqldump指令連權限我都試過了,即使把整個資料夾含檔案的權限改成777。(一樣cron執行過後卻無備份檔出現)

去看看/var/log/cron有執行過
程式碼:
Jul  8 07:36:00 TwsPC /usr/sbin/cron[32978]: (root) CMD (/root/data_backup/mysqldb/mysqldb_backup.sh)

然後我在把/var/log/cron檔案上寫到我在7點36分執行過的指令/root/data_backup/mysqldb/mysqldb_backup.sh,這行貼到putty上得打指令的地方執行後結果也是ok的~

所以我的問題是以root身份執行crontab -e,不管是用mysqldump -uxxxx.....或是/root/xxxx/xxx/xxx.sh兩種方法,雖然我自己以root身份執行過都正常,但是在用root身份去編輯 crontab後讓cron幫我作之後就不行自動備份成功。 難過
在備份的資料夾裡但卻看不到備份的檔案產生,不知道有大大遇過用cron的mysqldump的問題嗎?
有解決方法是否可以提供一下。

我以前在Linux好像沒有這個問題 :roll:
--------------------------------------------------------------------------------
你所執行的指令,包含scripts裡的指令
最好都補上完整路徑,不然你的系統預設的$PATH不見得有你要執行的程式
-----------------------------------------------------------------------------
把路徑改成
程式碼:
/usr/local/bin/mysqldump
就ok了~

BloggerAds