Guest User

Untitled

a guest
Nov 18th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #
  4. # rsyncによる簡易バックアップスクリプト(サーバ側)
  5. # by Shigeru KANEMOTO
  6. # Public Domain
  7. #
  8. # /etc/passwd
  9. # backup:x:0:0:Backup Superuser:/root/backup:/root/backup/shell
  10. #
  11. # authorized_keysファイルでは、以下のように指定する。
  12. # commandオプションに、バックアップ元の名称を指定する。この名前でディレクトリが作成される。
  13. # command="sgk-HD160G",no-pty,no-port-forwarding ssh-rsa AAAAB3Nz...
  14. #
  15. # その他、sshd_configにはセキュリティ関係の設定が必要。
  16. # PAMをやめるとか。
  17. #
  18.  
  19. # Config
  20. RSYNC_CMD="/usr/bin/rsync"
  21. DF_CMD="/bin/df"
  22. BACKUP_TOPDIR="/backup" # バックアップ保存領域のトップ。この下にバックアップ元毎にディレクトリが作成される。
  23.  
  24. # Startup
  25. me="$0@`hostname`"
  26.  
  27. # Check
  28. if [ "$#" != 2 -o "$1" != "-c" ]; then
  29. echo "$me: set 'command=\"source-label\"' in the 'authorized_keys' file."
  30. exit 1
  31. fi
  32.  
  33. src="$2"
  34. target="$BACKUP_TOPDIR/$src"
  35. if [ ! -d "$target" ]; then
  36. echo "$me: Directory '$target' does not exist."
  37. exit 2
  38. fi
  39.  
  40. if [ -z "$SSH_ORIGINAL_COMMAND" ]; then
  41. echo "$me: set 'command=\"source label\"' in the 'authorized_keys' file."
  42. exit 3
  43. fi
  44. set $SSH_ORIGINAL_COMMAND
  45.  
  46. # Main
  47. case "$1" in
  48. rsync)
  49. if [ "$2" = "--server" ]; then
  50. shift
  51. # オプションだけをコピーする。
  52. while [ "$#" -gt 0 ]; do
  53. if expr -- "$1" : '[^-]' > /dev/null; then
  54. break
  55. fi
  56. av=(${av[*]} "$1")
  57. shift
  58. done
  59. shift
  60. dir=$(echo "$1" | sed -e 's,\.\.,,g')
  61. nice "$RSYNC_CMD" ${av[*]} . "$target/$dir"
  62. touch "$target/$dir"
  63. fi
  64. ;;
  65.  
  66. df)
  67. "$DF_CMD" "$target"
  68. ;;
  69.  
  70. *)
  71. echo "$me: $1: command not found"
  72. exit 4
  73. ;;
  74. esac
Add Comment
Please, Sign In to add comment