歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux編程 >> SHELL編程

linux shell備份腳本實例

備份腳本:

  備份網站內容

  #!/bin/bash

  #指定運行的腳本shell

  #運行腳本要給用戶執行權限

  bakdir=/backup

  month=`date +%m`

  day=`date +%d`

  year=`date +%Y`

  hour=`date +%k`

  min=`date +%M`

  dirname=$year-$month-$day-$hour-$min

  mkdir $bakdir/$dirname

  mkdir $bakdir/$dirname/conf

  mkdir $bakdir/$dirname/web

  mkdir $bakdir/$dirname/db

  #備份conf,檢測通過

  gzupload=upload.tgz

  cp /opt/apache2/conf/httpd.conf $bakdir/$dirname/conf/httpd.conf

  cd /opt/apache2/htdocs/php

  tar -zcvf $bakdir/$dirname/web/$gzupload ./upload

  #遠程拷貝的目錄要有可寫權限

  scp -r /backup/$dirname [email protected]:/backup

  備份數據庫:

  #!/bin/bash

  #指定運行的腳本shell

  #運行腳本要給用戶執行權限

  bakdir=/backup

  month=`date +%m`

  day=`date +%d`

  year=`date +%Y`

  hour=`date +%k`

  min=`date +%M`

  dirname=$year-$month-$day-$hour-$min

  mkdir $bakdir/$dirname

  mkdir $bakdir/$dirname/conf

  mkdir $bakdir/$dirname/web

  mkdir $bakdir/$dirname/db

  #熱備份數據庫

  cp /opt/mysql/my.cnf $bakdir/$dirname/db/my.cnf

  cd /opt/mysql

  mysqldump --opt -u zhy -p --password=1986 test>$bakdir/$dirname/db/test.sql

  mysqldump --opt -u zhy -p --password=1986 phpwind>$bakdir/$dirname/db/phpwind.sql

  #遠程拷貝的目錄要有可寫權限

  scp -r /backup/$dirname [email protected]:/backup

Copyright © Linux教程網 All Rights Reserved