strace的应用

查看程序在运行中读写哪些文件:
strace -e open 程序 2>&1
寻找不能打开某个文件的原因:
strace -e open,access 2>&1 | grep 文件

查看正在运行的程序:
strace -p 程序ID

分析所花时间:
strace -c -p 程序ID

分析网络连接状况:
strace -e poll,select,connect,recvfrom,sendto nc www.baidu.com 80

fritz.box使用技巧

在fritz.box上安装服务:http://www.freetz.org

FritzRepass:从fritz.box里读出上网,网上电话等密码:http://svsload.com/wd/fritzrepass/

在dhcp里设置固定IP地址

  • 安装dhcping,并为网卡物理地址(MAC)预定IP地址apt-get install dhcping dhcping -s fritz.box -h <MAC> -c <预定IP>

     

  • 绑定MAC和IP地址
    • http://fritz.box
    • Einstellungen => System => Netzwerk=> 选择要设置的电脑,然后按*Eintrag bearbeiten*
    • 选择”immer die gleiche IP-Adresse zuweisen”

更新电信网络IP地址(DSL)

  • 以下方法均运用ForceTermination函数,更新IP地址
    使用cURLcurl "http://fritz.box:49000/upnp/control/WANIPConn1" -H 'Content-Type: text/xml; charset="utf-8"' -H 'SoapAction: urn:schemas-upnp-org:service:WANIPConnection:1#ForceTermination' -d '<?xml version="1.0" encoding="utf-8"?> <s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s=">http://schemas.xmlsoap.org/soap/envelope/" <s:Body> <u:ForceTermination xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1" /> </s:Body> </s:Envelope>'使用wget

    wget -d "http://fritz.box:49000/upnp/control/WANIPConn1"\

    --header='Content-Type: text/xml; charset="utf-8"'\

    --header='SoapAction: urn:schemas-upnp-org:service:WANIPConnection:1#ForceTermination'\

    --post-data='<?xml version="1.0" encoding="utf-8"?> <s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s=">http://schemas.xmlsoap.org/soap/envelope/" <s:Body> <u:ForceTermination xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1" /> </s:Body> </s:Envelope>'

Labels parameters

我的文件夹备份计划

我的文件夹备份计划

记录时间:2011-02-18

母备份脚本

  • 设定全局函数
  • 把之前的备份复制到指定的文件夹
  • 运行子备份计划
  • 文件名:backup-parent.bat
    • MY_HOME:我的文件夹所在地
ECHO OFF
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION

REM == configuration ==
ECHO Reading configuration ...
SET backup_scripts=%MY_HOME%\scripts\backups
SET old_target_dir=D:\backup\2cn.de_old
REM == global configuration ==
SET excluded_dirs=.svn,*.bak,target,.metadata,.settings
SET excluded_files=*.bak,*.log,.classpath,.project
REM SET target_dir=d:\backup
SET target_dir=D:\backup\2cn.de
REM SET packer_cmd=%ProgramFiles%\7-Zip\7z.exe
SET packer_cmd=%MY_HOME%\tools\LiberKey\Apps\7Zip\App\7-Zip\x86\7z.exe
SET packer_opts=-p=yun a  -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on
SET date_delimeter=.
SET temp_dir=%TEMP%\backup

REM == validation ==
ECHO Validating configuration  ...
IF NOT EXIST "%packer_cmd%" (
  ECHO No packer found in the location: %packer_cmd%
  GOTO end
)

REM == moving old backups ==
ECHO Moving old backups to OLD folder ...
IF EXIST "%target_dir%" (
  IF EXIST "%old_target_dir%" DEL /f /s /q "%old_target_dir%"\*.*
  MKDIR "%old_target_dir%"
  MOVE /y %target_dir%\*.* %old_target_dir%\
)

REM == running child backups ==
ECHO Running child backup scripts ...
FOR /f "delims=" %%A IN ('dir /s/b/a-d %backup_scripts%\*.bat') DO (
  SET current_backup=%%~A
  ECHO - running !current_backup! ...
  START "!DO NOT CLOSE! Running !current_backup! ... " /belownormal /wait !current_backup!
  ECHO - !current_backup! done
)
ECHO Done running child backups

:end
DATE /t
TIME /t

ENDLOCAL

子备份脚本

  • 检查环境设定
  • 复制备份文件到临时文件夹
  • 删除不需要备份的文件夹及文件
  • 压缩临时文件夹到指定位置
  • 删除临时文件夹
ECHO OFF
SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION


REM == configuration ==
ECHO Reading configuration ...
SET backup_name=
SET backup_dirs=
REM == project specific configuration (overwrites globals) ==
IF "%target_dir%"=="" SET target_dir=d:\backup\2cn.de
IF "%packer_cmd%"=="" SET packer_cmd=%MY_HOME%\tools\LiberKey\Apps\7Zip\App\7-Zip\x86\7z.exe
IF "%packer_opts%"=="" SET packer_opts=-p=yun a -tzip -r -mx5
IF "%date_delimeter%"=="" SET date_delimeter=.
IF "%temp_dir%"=="" SET temp_dir=%TEMP%\backup

REM == validation ==
ECHO Validating configuration  ...
ECHO backup_name=%backup_name%
ECHO bakcup_dirs=%backup_dirs"
ECHO target_dir=%target_dir%
ECHO packer_cmd=%packer_cmd%
ECHO packer_opts=%packer_opts%
ECHO date_delimeter=%date_delimeter%
ECHO temp_dir=%temp_dir%
IF NOT EXIST "%packer_cmd%" (
  ECHO No packer found in the location: %packer_cmd%
  GOTO end
)
FOR %%A IN (%backup_dirs%) DO (
  SET current_dir=%%~A
  IF NOT EXIST "!current_dir!" (
    ECHO Check backup_dirs configuration. Backup directory "!current_dir!" doesn't exist!
  )
)

REM == initialization ==
ECHO Initialializing ...
FOR /f "tokens=1,2,3 delims=%date_delimeter% " %%a IN ('date /t') DO (
  SET current_date=%%c%%b%%a
)
FOR /f "tokens=1,2 delims=: " %%a IN ('time /t') DO (
  SET current_time=%%a%%b
)
SET file_ts=%current_date%%current_time%


REM == preparation ==
ECHO Preparing temporary snapshot ...
IF NOT EXIST "%temp_dir%" MKDIR "%temp_dir%"
FOR %%A IN (%backup_dirs%) DO (
  SET current_dir=%%~A
  ECHO - copying !current_dir! ...
  SET dest_dir=%temp_dir%\!current_dir:~0,1!%%~pnxA
  XCOPY "!current_dir!" "!dest_dir!" /v /c /i /g /h /q /r /y /e
)

REM == assembly ==
ECHO  Packaging ...
SET target_output=%target_dir%\%backup_name%_%file_ts%.zip
ECHO Target output name is %target_output%
IF EXIST "%target_output%" DEL /f /q "%target_output%"
START "!DO NOT CLOSE! Compressing ... " /belownormal /wait "%packer_cmd%" %packer_opts% "%target_output%" "%temp_dir%\*"
ECHO Done compressing backed up files



REM == cleanup ==
ECHO Cleaning up ...
IF EXIST "%temp_dir%" RMDIR /s /q "%temp_dir%"

:end
TIME /t

ENDLOCAL 
 
EXIT 0

设置定时任务计划

  • 任务开始:开机后在电脑空闲30分钟的情况下启动备份计划

系统备份

系统备份

记录时间:2011-03-01

Clonezilla备份盘

  1. 启动盘:partedmagic: pmagic-5.10.iso
  2. 启动后删除/bin/pigz的链接
    • rm /bin/pigz

备份分区

  1. 使用Clonezilla备份硬盘分区
    • 选择device-image
    • 选择local_dev
    • 按Enter键
    • 选择用作储存备份的分区:例如sdc1
    • 选择/作为储存备份的文件夹
    • 按Enter键
    • 选择Beginner
    • 选择saveparts
    • 存储文件名:例如win7-2011-02-28-img
    • 选择要备份的分区:例如sda3(win7)
    • 在注释里写入日期,系统以及分区号
    • 写入y确定,然后按Enter键
  2. 把备份文件夹归类:例如复制到G:\system\samsung_r540\win7-2011-02-28-img

还原分区

  1. 将需要还原的系统备份文件夹移到分区最外面:例如把win7备份文件夹复制到G:\win7-2011-02-28-img
  2. 启动Clonezilla
    • 选择device-image
    • 选择local_dev
    • 按Enter键
    • 选择用作储存备份的分区:例如sdc1
    • 选择/作为需要备份文件夹所在地
    • 选择win7备份文件夹还原分区
    • 写入两次y确定开始还原