LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
12
返回列表 发新帖
楼主: harttmann

/usr有4.1G,根目录用了9.1G,/home 和/var都在单独的分区上,正常么?

[复制链接]
发表于 2009-6-3 07:24:52 | 显示全部楼层
备份我用stage4,从gentoo-wiki上copy下来的:
  1. #!/bin/bash
  2. # Backup script for Gentoo Linux
  3. #
  4. # mkstage4.sh is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # mkstage4.sh is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. # GNU General Public License for more details.
  13. #
  14. # Copyright: Reto Glauser aka blinkeye
  15. # Mailto: stage4 at blinkeye dot ch
  16. # Homepage: http://blinkeye.ch
  17. # Forum post: http://forums.gentoo.org/viewtopic-t-312817.html
  18. # Date: 2009-04-02
  19. version=v3.7
  20. basename=`basename $0`
  21. find=/usr/bin/find
  22. tar=/bin/tar
  23. # these are the commands we actually need for the backup
  24. command_list=(cut date echo $find grep hostname mount sh split $tar umount uname which)
  25. # verify that each command we use exists. if one can't be found use $PATH and make a suggestion if possible.
  26. for command in ${command_list[@]}; do
  27.         if [ ! -x "`which $command 2>&1`" ]; then
  28.                 echo -e "\nERROR: $command not found! "
  29.                 base=`basename $command`
  30.                 if [ "`which $base 2>&1 | grep "no \`basename $command\` in"`" != "" ]; then
  31.                         echo -e "ERROR: $base is not in your \$PATH."
  32.                 fi
  33.                 exit -1
  34.         fi
  35. done
  36. help="\nUsage:\n\nsh `basename $0` [[-v]|[--verbose]] [[-s]|[--split]] \n\nTo run the script NOT in verbose mode comes in handy if you want to see only the errors that occur during the backup.\n"
  37. # Defaults to creating one tarball
  38. tar_output="--file"
  39. # split command
  40. split_options="--suffix-length=1 --bytes=685m"
  41. # options for the tar command
  42. tarOptions=" --preserve-permissions --create --absolute-names --totals --ignore-failed-read"
  43. # where to put the stage4
  44. stage4Location=/mnt/backups/stage4
  45. # name prefix
  46. stage4prefix=`hostname`-stage4-`date +\%Y.\%m.\%d`
  47. # patterns which should not be backed up (like iso files).
  48. # example: default_exclude_pattern="*.iso *.divx"
  49. # These pattern count only for files NOT listed in the $custom_include_list.
  50. default_exclude_pattern=""
  51. # these files/directories are always excluded. don't add trailing slashes.
  52. # don't touch it unless you know what you are doing!
  53. # /var/db and /var/cache/edb are intentionally added here. they are listed
  54. # in $default_include_folders
  55. default_exclude_list="
  56. /dev
  57. /lost+found
  58. /mnt
  59. /proc
  60. /sys
  61. /tmp
  62. /usr/portage
  63. /usr/src
  64. /var/log
  65. /var/tmp
  66. /var/db
  67. /var/cache/edb
  68. $stage4Location
  69. `echo $CCACHE_DIR`"
  70. # files/devices/folders, which need to be backed up (preserve folder structure).
  71. # don't touch it unless you know what you are doing! no recursive backup of folders.
  72. # use $default_include_folders instead.
  73. default_include_files="
  74. /dev/null
  75. /dev/console
  76. /home
  77. /mnt
  78. `find /mnt -name .keep`
  79. /proc
  80. /sys
  81. /tmp
  82. /usr/portage
  83. /usr/src
  84. /var/log/emerge.log
  85. /usr/src/linux-`uname -r`/.config"
  86. # folders, which need to be backed up recursively on every backup.
  87. # don't touch it unless you know what you are doing! the reason for this
  88. # variable is that some users add /var to the $default_exclude_list. here
  89. # we ensure that portage's memory is backed up in any case.
  90. default_include_folders="
  91. /var/db"
  92. # IMPORTANT: A minimal backup will EXCLUDE files/folders listed here. A custom backup will
  93. # include/exclude these files/folders depening on your answer.
  94. custom_include_list="
  95. /home/*
  96. /usr/src/linux-`uname -r`"
  97. # add files/folders here which are subfolders of a folder listed in $custom_include_list which should NOT
  98. # be backed up. eg.
  99. #custom_exclude_list="/home/foo/mp3 /home/foo/downloads /home/foo/.*"
  100. custom_exclude_list=""
  101. # Only files/folders within the $custom_include_list are checked against these patterns
  102. # custom_exclude_pattern="*.mp3 *.iso"
  103. custom_exclude_pattern=""
  104. # the find_command
  105. find_command="$find /*"
  106. # don't backup anything which matches pattern listed in $default_exclude_pattern
  107. for pattern in $default_exclude_pattern; do
  108.         find_command="$find_command -not -name $pattern"
  109. done
  110. # assemble the find_command
  111. function find_files()
  112. {
  113.         for folder in $default_exclude_list; do
  114.                 find_command="$find_command -path $folder -prune -o"
  115.         done
  116.         find_command="$find_command -print"
  117.         for i in $default_include_files; do
  118.                 find_command="echo $i; $find_command"
  119.         done
  120.         for i in $default_include_folders; do
  121.                 if [ -d $i ]; then
  122.                         find_command="$find $i; $find_command"
  123.                 else
  124.                         find_command="echo $i; $find_command"
  125.                 fi
  126.         done
  127. }
  128. # check the exclude/include variables for non-existing entries
  129. function verify()
  130. {
  131.         for i in $1; do
  132.                 if [ ! -e "`echo "$i" | cut -d'=' -f2 | cut -d'*' -f1`" -a "$i" != "/lost+found" -a "$i" != "$stage4Location" ]; then
  133.                         echo "ERROR: `echo "$i" | cut -d'=' -f2` not found! Check your "$2
  134.                         exit 0
  135.                 fi
  136.         done
  137. }
  138. # check input parameters
  139. while [ $1 ]; do
  140.         case  $1 in
  141.         "-h" | "--help")
  142.                 echo -e $help
  143.                 exit 0;;
  144.         "-v" | "--verbose")
  145.                 verbose=$1;;
  146.         "-s" | "--split")
  147.                 tar_output="--split";;
  148.         "");;
  149.         *)
  150.                 echo -e $help
  151.                 exit 0;;
  152.         esac
  153.         shift
  154. done
  155. echo ""
  156. # check folder/files listed in $default_exclude_list exist
  157. verify "$default_exclude_list" "\$default_exclude_list"
  158. # check files listed in $default_include_files exist
  159. verify "$default_include_files" "\$default_include_files"
  160. # check folder listed in $default_include_folders exist
  161. verify "$default_include_folders" "\$default_include_folders"
  162. #check folder listed in $custom_include_list exist
  163. verify "$custom_include_list" "\$custom_include_list"
  164. #check folder listed in $custom_exclude_list exist
  165. verify "$custom_exclude_list" "\$custom_exclude_list"
  166. # print out the version
  167. echo -e "\nBackup script $version"
  168. echo -e "=================="
  169. # how do you want to backup?
  170. echo -e "\nWhat do you want to do? (Use CONTROL-C to abort)\n
  171. Fast (tar.gz):
  172. (1) Minimal backup
  173. (2) Interactive backup
  174. Best (tar.lzma):
  175. (3) Minimal backup
  176. (4) Interactive backup\n"
  177. while [ "$option" != '1' -a "$option" != '2' -a "$option" != '3' -a "$option" != '4' ]; do
  178.         echo -en "Please enter your option: "
  179.         read option
  180. done
  181. case $option in
  182. [1,3])
  183.         stage4Name=$stage4Location/$stage4prefix-minimal.tar;;
  184. [2,4])
  185.         stage4Name=$stage4Location/$stage4prefix-custom.tar
  186.         for folder in $custom_include_list; do
  187.                 echo -en "\nDo you want to backup" `echo "$folder" | cut -d'=' -f2`"? (y/n) "
  188.                 read answer
  189.                 while [ "$answer" != 'y' -a "$answer" != 'n' ]; do
  190.                         echo -en "Do you want to backup" `echo "$folder" | cut -d'=' -f2`"? (y/n) "
  191.                         read answer
  192.                 done
  193.                 if [ "$answer" == 'n' ]; then
  194.                         find_command="$find_command -path $folder -prune -o"
  195.                 else
  196.                         custom_find="$find $folder"
  197.                         for i in $custom_exclude_pattern; do
  198.                                 custom_find="$custom_find -name $i -o"
  199.                         done
  200.                         for i in $custom_exclude_list; do
  201.                                 custom_find="$custom_find -path $i -prune -o"
  202.                         done
  203.                         find_command="$custom_find -print; $find_command"
  204.                 fi
  205.         done ;;
  206. esac
  207. # add $custom_include_list to the $default_exclude_list as we assembled
  208. # $custom_find with $custom_include_list already.
  209. default_exclude_list="$default_exclude_list $custom_include_list"
  210. case $option in
  211. [1,2])
  212.         stage4postfix="gz"
  213.         zip="--gzip";;
  214. [3,4])
  215.         stage4postfix="lzma"
  216.         zip="--lzma";;
  217. esac
  218. # mount boot
  219. echo -e "\n* mounting boot"
  220. mount /boot >/dev/null 2>&1
  221. # find the files/folder to backup
  222. find_files
  223. find_command="($find_command)"
  224. # create the final command
  225. if [ "$tar_output" == "--file" ]; then
  226.         tar_command="$find_command | $tar $zip $tarOptions $verbose --file $stage4Name.$stage4postfix --no-recursion -T -"
  227. else
  228.         tar_command="$find_command | $tar $zip $tarOptions $verbose --no-recursion -T - | split $split_options - "$stage4Name.$stage4postfix"_"
  229. fi
  230. if [ "$verbose" ]; then
  231.         echo -e "\n* creating the stage4 in $stage4Location with the following command:\n\n"$tar_command
  232. fi
  233. # everything is set, are you sure to continue?
  234. echo -ne "\nDo you want to continue? (y/n) "
  235. read answer
  236. while [ "$answer" != 'y' ] && [ "$answer" != 'n' ]; do
  237.         echo -ne "Do you want to continue? (y/n) "
  238.         read answer
  239. done
  240. if [ "$answer" == 'y' ]; then
  241.         # check whether the file already exists.
  242.         if [ "$tar_output" == "--split" ]; then
  243.                 overwrite="`ls "$stage4Name.$stage4postfix"_* 2>&1 | grep -v 'No such file'`"
  244.         else
  245.                 overwrite="$stage4Name.$stage4postfix"
  246.         fi
  247.         if [ -a "`echo "$overwrite" | grep "$overwrite" -m1`" ]; then
  248.                 echo -en "\nDo you want to overwrite $overwrite? (y/n) "
  249.                 read answer
  250.                 while [ "$answer" != 'y' ] && [ "$answer" != 'n' ]; do
  251.                         echo -en "Do you want to overwrite $overwrite? (y/n) "
  252.                         read answer
  253.                 done
  254.                 if [ "$answer" == 'n' ]; then
  255.                         echo -e "\n* There's nothing to do ... Exiting"
  256.                         exit 0;
  257.                 fi
  258.         fi
  259.         # if necessary, create the stage4Location
  260.         if [ ! -d "$stage4Location" ] ; then
  261.                 echo "* creating directory $stage4Location"
  262.                 mkdir -p $stage4Location
  263.         fi
  264.         echo -e "\n* Please wait while the stage4 is being created.\n"
  265.         # do the backup.
  266.         sh -c "$tar_command"
  267.         # finished, clean up
  268.         echo -e "\n* stage4 is done"
  269.         echo "* umounting boot"
  270.         umount /boot >/dev/null 2>&1
  271.         # Integrity check
  272.         echo -e "* Checking integrity"
  273.         if [ "$zip" == "--gzip" ]; then
  274.                 zip="gzip"
  275.         else
  276.                 zip="lzma"
  277.         fi
  278.         if [ "$tar_output" == "--split" ]; then
  279.                 if [ "`cat "$stage4Name.$stage4postfix"_*"" | $zip --test 2>&1`" != "" ]; then
  280.                         echo -e "* Integrity check failed. Re-run the script and check your hardware."
  281.                         exit -1
  282.                 fi
  283.         else
  284.                 if [ "`$zip --test  $stage4Name.$stage4postfix 2>&1`" != "" ]; then
  285.                         echo -e "* Integrity check failed. Re-run the script and check your hardware."
  286.                         exit -1
  287.                 fi
  288.         fi
  289.         # everything went smoothly
  290.         echo -e "* Everything went smoothly. You successfully created a stage4."
  291. else
  292.         echo -e "\n* There's nothing to do ... Exiting"
  293. fi
复制代码
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表