CentOS系统备份脚本详解

04-08

  #!/bin/sh

  #设定变量

  bak_path=/root/bak_linux

  date=$(date +%Y%m%d)

  log_file=$bak_path/$date#log.log

  #把执行结果写到日志中

  exec 1>>$log_file 2>&1

  #把要备份的目录打包放到$bak_path目录下

  tar -zcvf $bak_path/$date#boot.tar.gz /boot

  tar -zcvf $bak_path/$date#etc.tar.gz /etc

  tar -zcvf $bak_path/$date#var.tar.gz /var

  echo "############\n"

  echo $?

  #上传备份文件

  ftp -i -n -v << FTPIT

  open 192.168.0.27

  user 111 111

  binary

  lcd $bak_path

  mput *.tar.gz

  put *#log.log

  by

  FTPIT

  echo "############\n"

  echo $?

  #删除上传完毕的.tar和.log文件

  rm -rf $bak_path/*#*.tar

  rm -rf $bak_path/*#log.log