Last active
December 30, 2018 22:34
-
-
Save k4zuki02h4t4/3d090c73702eac28fc64021289598be0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Windows thumbnail cache files | |
Thumbs.db | |
ehthumbs.db | |
ehthumbs_vista.db | |
# Dump file | |
*.stackdump | |
# Folder config file | |
[Dd]esktop.ini | |
# Recycle Bin used on file shares | |
$RECYCLE.BIN/ | |
# Windows Installer files | |
*.cab | |
*.msi | |
*.msix | |
*.msm | |
*.msp | |
# Windows shortcuts | |
*.lnk | |
# General | |
.DS_Store | |
.AppleDouble | |
.LSOverride | |
# Icon must end with two \r | |
Icon | |
# Thumbnails | |
._* | |
# Files that might appear in the root of a volume | |
.DocumentRevisions-V100 | |
.fseventsd | |
.Spotlight-V100 | |
.TemporaryItems | |
.Trashes | |
.VolumeIcon.icns | |
.com.apple.timemachine.donotpresent | |
# Directories potentially created on remote AFP share | |
.AppleDB | |
.AppleDesktop | |
.apdisk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Set the date format, filename and the directories where your backup files will be placed and which directory will be archived. | |
NOW=$(date +"%Y%m%d%H%M") | |
NAME="kucklu.me" | |
SLUG="${NAME}-backup" | |
FILE="${SLUG}-${NOW}.tar" | |
USER="kir000000" | |
GROUP="kirusr" | |
#atime 最終アクセス時刻 (access time) | |
#mtime 最終変更時刻 (modify time) | |
#ctime 最終ステータス変更時刻 (change time) | |
#-mtime +2 更新日が3日より前 | |
#-mmin +2 更新日が3分より前 | |
GENERATION="-mmin +180" | |
USER_DIR="/home/kir000000" | |
LOG_DIR="${USER_DIR}/log" | |
PIBLIC_DIR="${USER_DIR}/public_html" | |
BACKUP_DIR="${USER_DIR}/backup/${NAME}" | |
WWW_DIR="${PIBLIC_DIR}/${NAME}" | |
# MySQL database credentials | |
DB_USER="" | |
DB_PASS="" | |
DB_NAME="" | |
DB_HOST="localhost" | |
DB_FILE="${SLUG}-${NOW}.sql" | |
cat <<EOF >> ${LOG_DIR}/cron.log | |
$(date +"%Y-%m-%d %H:%M") ${NAME} - バックアップスタート | |
EOF | |
if [ ! -e "${BACKUP_DIR}" ]; then | |
mkdir -m 755 -p "${BACKUP_DIR}" | |
fi | |
tar -cf "${BACKUP_DIR}/${FILE}" -C "${PIBLIC_DIR}" ${NAME} | |
if [ -x "`which mysqldump`" ]; then | |
mysqldump -u ${DB_USER} -p$DB_PASS -h ${DB_HOST} --opt --skip-lock-tables --single-transaction -r "${BACKUP_DIR}/${DB_FILE}" ${DB_NAME} | |
cat <<EOF >> ${LOG_DIR}/cron.log | |
$(date +"%Y-%m-%d %H:%M") ${NAME} - データベースサイズ $(du -m "${BACKUP_DIR}/${DB_FILE}") | |
EOF | |
tar --append --file="${BACKUP_DIR}/${FILE}" -C "${BACKUP_DIR}" ${DB_FILE} | |
rm "${BACKUP_DIR}/${DB_FILE}" | |
fi | |
gzip -9 "${BACKUP_DIR}/${FILE}" | |
find "${BACKUP_DIR}"/*.tar.gz ${GENERATION} -print0 | xargs -0 rm -rf | |
chown -R ${USER}:${GROUP} "${BACKUP_DIR}" | |
cat <<EOF >> ${LOG_DIR}/cron.log | |
$(date +"%Y-%m-%d %H:%M") ${NAME} - バックアップ終了 | |
EOF | |
${USER_DIR}/bin/rclone.sh --bin "${USER_DIR}/bin" --backup "${BACKUP_DIR}" --ignore "${USER_DIR}/.config/rclone/.rcloneignore" --remote "Server/Backup/${USER}/${NAME}" --remote-name gdrive | |
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Label</key> | |
<string>com.kuck1u.monitoring.example</string> | |
<key>ProgramArguments</key> | |
<array> | |
<string>/Users/tomiyasu/Local Sites/example/bin/monitoring.sh</string> | |
</array> | |
<key>StartInterval</key> | |
<integer>300</integer> | |
<key>StandardOutPath</key> | |
<string>/Users/tomiyasu/Local Sites/example/log/monitoring.log</string> | |
<key>StandardErrorPath</key> | |
<string>/Users/tomiyasu/Local Sites/example/log/monitoring.error.log</string> | |
</dict> | |
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>Label</key> | |
<string>com.kuck1u.remotebackup.kir000000</string> | |
<key>ProgramArguments</key> | |
<array> | |
<string>/Users/kuck1u/Local Sites/backups/kir000000/rsync.sh</string> | |
</array> | |
<key>StartInterval</key> | |
<integer>3600</integer> | |
<key>StandardOutPath</key> | |
<string>/Users/kuck1u/log/remotebackup.kir000000.log</string> | |
<key>StandardErrorPath</key> | |
<string>/Users/kuck1u/log/remotebackup.kir000000.err.log</string> | |
</dict> | |
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
API_KEY="examp1e0000000examp1e0000000" | |
ROOM_ID="00000000000" | |
SITE_NAME="EXAMPLE" | |
SITE_URL="http://example.com" | |
HTTP=$( curl -LI ${SITE_URL} -o /dev/null -w '%{http_code}\n' -s ) | |
if [ ${HTTP} != "200" ]; then | |
curl -s -o /dev/null -X POST -H "X-ChatWorkToken: ${API_KEY}" -d "body=[info][title]【${HTTP}】${SITE_NAME}のサーバーに異常を感知しました[/title]サイト URL: ${SITE_URL}[/info]&self_unread=1" "https://api.chatwork.com/v2/rooms/${ROOM_ID}/messages" | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
VALUE_BIN="/usr/local/bin" | |
VALUE_HOME="${HOME}" | |
FLAG_BACKUP=false | |
FLAG_REMOTE=false | |
FLAG_REMOTE_NAME=false | |
FLAG_DRY_RUN=false | |
FLAG_IGNORE=false | |
OPTIONS="--drive-use-trash=false --drive-upload-cutoff=32M --drive-chunk-size=32M" | |
for opt in "$@"; do | |
case "${opt}" in | |
'--bin' ) | |
VALUE_BIN="$2"; | |
shift | |
;; | |
'--home' ) | |
VALUE_HOME="$2"; | |
shift | |
;; | |
'--backup' ) | |
# オプションに続く値が 必須 の場合 | |
if [[ -z "$2" ]] || [[ "$2" =~ ^-+ ]]; then | |
echo "option requires an argument -- $( echo $1 | sed 's/^-*//' )" 1>&2 | |
exit 1 | |
fi | |
FLAG_BACKUP=true; | |
VALUE_BACKUP="$2"; | |
shift | |
;; | |
'--remote' ) | |
# オプションに続く値が 必須 の場合 | |
if [[ -z "$2" ]] || [[ "$2" =~ ^-+ ]]; then | |
echo "option requires an argument -- $( echo $1 | sed 's/^-*//' )" 1>&2 | |
exit 1 | |
fi | |
FLAG_REMOTE=true; | |
VALUE_REMOTE="$2"; | |
shift | |
;; | |
'--remote-name' ) | |
if [[ -z "$2" ]] || [[ "$2" =~ ^-+ ]]; then | |
echo "option requires an argument -- $( echo $1 | sed 's/^-*//' )" 1>&2 | |
exit 1 | |
fi | |
FLAG_REMOTE_NAME=true; | |
VALUE_REMOTE_NAME="$2"; | |
shift | |
;; | |
'--ignore' ) | |
FLAG_IGNORE=true; | |
VALUE_IGNORE="$2"; | |
shift | |
;; | |
'--dry-run' ) | |
FLAG_DRY_RUN=true; | |
shift | |
;; | |
'--' | '-' ) | |
shift | |
PARAM+=( "$@" ) | |
break | |
;; | |
-* ) | |
echo "${PROGNAME}: illegal option -- '$( echo $1 | sed 's/^-*//' )'" 1>&2 | |
exit 1 | |
;; | |
* ) | |
if [[ -n "$1" ]] && [[ ! "$1" =~ ^-+ ]]; then | |
PARAM+=( "$1" ); shift | |
fi | |
;; | |
esac | |
done | |
if [ ${FLAG_BACKUP} = true ] && [ ${FLAG_REMOTE} = true ] && [ ${FLAG_REMOTE_NAME} = true ] && [ -e "${VALUE_HOME}/.config/rclone/rclone.conf" ]; then | |
if [ ${FLAG_IGNORE} = true ]; then | |
OPTIONS="${OPTIONS} --exclude-from ${VALUE_IGNORE}" | |
fi | |
if [ ${FLAG_DRY_RUN} = true ]; then | |
OPTIONS="${OPTIONS} --dry-run" | |
fi | |
if [ ! -d "${VALUE_HOME}/log/" ]; then | |
mkdir -p "${VALUE_HOME}/log/" | |
fi | |
if [ ! -e "${VALUE_HOME}/log/rclone.log" ]; then | |
touch "${VALUE_HOME}/log/rclone.log" | |
fi | |
${VALUE_BIN}/rclone sync ${OPTIONS} ${VALUE_BACKUP} ${VALUE_REMOTE_NAME}:${VALUE_REMOTE} 2>&1 | tee -a ${VALUE_HOME}/log/rclone.log | |
${VALUE_BIN}/rclone dedupe ${OPTIONS} --dedupe-mode newest ${VALUE_REMOTE_NAME}:${VALUE_REMOTE} 2>&1 | tee -a ${VALUE_HOME}/log/rclone.log | |
${VALUE_BIN}/rclone cleanup ${OPTIONS} ${VALUE_REMOTE_NAME}: 2>&1 | tee -a ${VALUE_HOME}/log/rclone.log | |
fi | |
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
LOCAL="/Users/kuck1u/Local\ Sites/backups/kir000000/backup" | |
REMOTE="/kir000000/backup/" | |
REMOTE_HOST="kir000000@000.000.000.000" | |
PASSWORD="abcd1234efg5678" | |
expect -c " | |
set timeout -1 | |
spawn /usr/local/bin/rsync -au --iconv=UTF-8-MAC,UTF-8 --delete ${REMOTE_HOST}:${REMOTE} ${LOCAL} | |
expect \"password:\" | |
send \"${PASSWORD}\n\" | |
expect eof exit | |
" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# gdrive コマンドがあるディレクトリのパス | |
FLAG_C=false | |
# ユーザーのホームディレクトリのパス | |
FLAG_H=false | |
# バックアップ対象のディレクトリのパス | |
FLAG_B=false | |
# Google Drive のディレクトリ ID | |
FLAG_F=false | |
# Dry run | |
FLAG_D=false | |
OPTIONS="--keep-local --delete-extraneous --no-progress --timeout 0" | |
while getopts c:h:b:f:d OPT | |
do | |
case $OPT in | |
"c" ) FLAG_C=true ; VALUE_C="$OPTARG" ;; | |
"h" ) FLAG_H=true ; VALUE_H="$OPTARG" ;; | |
"b" ) FLAG_B=true ; VALUE_B="$OPTARG" ;; | |
"f" ) FLAG_F=true ; VALUE_F="$OPTARG" ;; | |
"d" ) FLAG_D=true ;; | |
esac | |
done | |
if [ ${FLAG_C} = true ] && [ ${FLAG_H} = true ] && [ ${FLAG_B} = true ] && [ ${FLAG_F} = true ]; then | |
if [ ${FLAG_D} = true ]; then | |
OPTIONS="${OPTIONS} --dry-run" | |
fi | |
${VALUE_C}/gdrive --config ${VALUE_H}/.gdrive sync upload ${OPTIONS} ${VALUE_B} ${VALUE_F} 2>&1 | tee -a ${VALUE_H}/log/gdrive.log | |
fi | |
exit 0 |
Author
k4zuki02h4t4
commented
Nov 7, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment