Skip to content

Instantly share code, notes, and snippets.

@andromedarabbit
Last active August 6, 2018 00:39
Show Gist options
  • Save andromedarabbit/02c6473b61c60b2c30367b4f52cfa07e to your computer and use it in GitHub Desktop.
Save andromedarabbit/02c6473b61c60b2c30367b4f52cfa07e to your computer and use it in GitHub Desktop.

Revisions

  1. andromedarabbit revised this gist Aug 6, 2018. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion backup-to-gdfs.sh
    Original file line number Diff line number Diff line change
    @@ -24,8 +24,9 @@ do
    done

    # rsync_tmbackup.sh는 hardlink를 활용하는데 Google File Stream에선 하드링크된 파일을 복사본으로 취급하기 때문에 사실상 매번 모든 파일을 다 복사하는 꼴이 된다.
    # rsync_tmbackup.sh는 공백 문자가 들어간 경로를 잘 처리 못하는 버그가 있는 듯 하다. https://github.com/laurent22/rsync-time-backup/issues/116
    SRC_DIRS=(
    "${HOME}/dotfiles"
    # "${HOME}/dotfiles"
    )

    for ix in ${!SRC_DIRS[*]}
    @@ -41,6 +42,7 @@ done
    # See https://www.reddit.com/r/linux/comments/3cnn54/just_a_reminder_on_multi_core_systems_use_pigz/
    SRC_DIRS=(
    "${HOME}/Documents"
    "${HOME}/dotfiles"
    )

    for ix in ${!SRC_DIRS[*]}
  2. andromedarabbit revised this gist Aug 6, 2018. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion backup-to-gdfs.sh
    Original file line number Diff line number Diff line change
    @@ -31,7 +31,6 @@ SRC_DIRS=(
    for ix in ${!SRC_DIRS[*]}
    do
    SRC_DIR=${SRC_DIRS[$ix]}
    BASENAME="$(basename ${SRC_DIR})"
    TARGET_DIR="/Volumes/GoogleDrive/My Drive/백업/Snapshots"
    mkdir -p -- "${TARGET_DIR}"
    touch "${TARGET_DIR}/backup.marker"
  3. andromedarabbit revised this gist Aug 6, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion backup-to-gdfs.sh
    Original file line number Diff line number Diff line change
    @@ -35,7 +35,7 @@ do
    TARGET_DIR="/Volumes/GoogleDrive/My Drive/백업/Snapshots"
    mkdir -p -- "${TARGET_DIR}"
    touch "${TARGET_DIR}/backup.marker"
    rsync_tmbackup.sh "${HOME}/${BASENAME}" "${TARGET_DIR}" "${THIS_DIR}/rsync-exclude-patterns.txt"
    rsync_tmbackup.sh "${SRC_DIR}" "${TARGET_DIR}" "${THIS_DIR}/rsync-exclude-patterns.txt"
    done

    # 용량이 작은 텍스트 파일이 많은 경우에는 작업 폴더 전체를 압축해서 백업하는 편이 시간이 덜 걸린다. 병렬 압축을 지원하는 pigz 같은 도구를 이용하면 파일 숫자가 많아도 걱정할 필요가 없다.
  4. andromedarabbit revised this gist Aug 6, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions backup-to-gdfs.sh
    Original file line number Diff line number Diff line change
    @@ -35,7 +35,7 @@ do
    TARGET_DIR="/Volumes/GoogleDrive/My Drive/백업/Snapshots"
    mkdir -p -- "${TARGET_DIR}"
    touch "${TARGET_DIR}/backup.marker"
    echo rsync_tmbackup.sh "${HOME}/${BASENAME}" "${TARGET_DIR}" "${THIS_DIR}/rsync-exclude-patterns.txt"
    rsync_tmbackup.sh "${HOME}/${BASENAME}" "${TARGET_DIR}" "${THIS_DIR}/rsync-exclude-patterns.txt"
    done

    # 용량이 작은 텍스트 파일이 많은 경우에는 작업 폴더 전체를 압축해서 백업하는 편이 시간이 덜 걸린다. 병렬 압축을 지원하는 pigz 같은 도구를 이용하면 파일 숫자가 많아도 걱정할 필요가 없다.
    @@ -56,7 +56,7 @@ do

    mkdir -p "${TARGET_DIR}"

    pushd "$(dirname ${SRC_DIR})Sublime/"
    pushd "${SRC_DIR})/.."
    tar -c "${BASENAME}" | pigz --fast -p ${THREADS} -c | split -a 5 -d -b "3000M" - "${TARGET_DIR}/${TARGET_FILENAME}"
    popd

  5. andromedarabbit revised this gist Aug 2, 2018. No changes.
  6. andromedarabbit revised this gist Aug 2, 2018. 1 changed file with 11 additions and 12 deletions.
    23 changes: 11 additions & 12 deletions backup-to-gdfs.sh
    Original file line number Diff line number Diff line change
    @@ -7,36 +7,35 @@ type pigz || brew install pigz
    type rsync || brew install rsync
    type rsync-time-backup.sh || brew install rsync-time-backup

    # Backup
    # rsync_tmbackup.sh는 hardlink를 활용하는데 Google File Stream에선 하드링크된 파일을 복사본으로 취급하기 때문에 사실상 매번 모든 파일을 다 복사하는 꼴이 된다.
    SRC_DIRS=(
    "${HOME}/dotfiles"
    "${HOME}/Movies"
    "${HOME}/Music"
    "${HOME}/Downloads"
    "${HOME}/Desktop"
    )

    for ix in ${!SRC_DIRS[*]}
    do
    SRC_DIR=${SRC_DIRS[$ix]}
    BASENAME="$(basename ${SRC_DIR})"
    TARGET_DIR="/Volumes/GoogleDrive/My Drive/백업/Snapshots"
    mkdir -p -- "${TARGET_DIR}"
    touch "${TARGET_DIR}/backup.marker"
    echo rsync_tmbackup.sh "${HOME}/${BASENAME}" "${TARGET_DIR}" "${THIS_DIR}/rsync-exclude-patterns.txt"
    BACKUP_DIR="/Volumes/GoogleDrive/My Drive/백업/Backups/${BASENAME}$(date +\%Y-\%m-\%d)"
    rsync -av -delete --backup --backup-dir="${BACKUP_DIR}" "${SRC_DIR}" "${TARGET_DIR}" --exclude-from "${THIS_DIR}/rsync-exclude-patterns.txt"
    done

    # rsync_tmbackup.sh는 hardlink를 활용하는데 Google File Stream에선 하드링크된 파일을 복사본으로 취급하기 때문에 사실상 매번 모든 파일을 다 복사하는 꼴이 된다.
    SRC_DIRS=(
    "${HOME}/Movies"
    "${HOME}/Music"
    "${HOME}/Downloads"
    "${HOME}/Desktop"
    "${HOME}/dotfiles"
    )

    for ix in ${!SRC_DIRS[*]}
    do
    SRC_DIR=${SRC_DIRS[$ix]}
    BASENAME="$(basename ${SRC_DIR})"
    TARGET_DIR="/Volumes/GoogleDrive/My Drive/백업/Snapshots"
    BACKUP_DIR="/Volumes/GoogleDrive/My Drive/백업/Backups/${BASENAME}$(date +\%Y-\%m-\%d)"
    rsync -av -delete --backup --backup-dir="${BACKUP_DIR}" "${SRC_DIR}" "${TARGET_DIR}" --exclude-from "${THIS_DIR}/rsync-exclude-patterns.txt"
    mkdir -p -- "${TARGET_DIR}"
    touch "${TARGET_DIR}/backup.marker"
    echo rsync_tmbackup.sh "${HOME}/${BASENAME}" "${TARGET_DIR}" "${THIS_DIR}/rsync-exclude-patterns.txt"
    done

    # 용량이 작은 텍스트 파일이 많은 경우에는 작업 폴더 전체를 압축해서 백업하는 편이 시간이 덜 걸린다. 병렬 압축을 지원하는 pigz 같은 도구를 이용하면 파일 숫자가 많아도 걱정할 필요가 없다.
  7. andromedarabbit revised this gist Aug 2, 2018. No changes.
  8. andromedarabbit revised this gist Aug 2, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion backup-to-gdfs.sh
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ fi

    type pigz || brew install pigz
    type rsync || brew install rsync
    type rsync-time-backup.sh
    type rsync-time-backup.sh || brew install rsync-time-backup

    # Backup
    # rsync_tmbackup.sh는 hardlink를 활용하는데 Google File Stream에선 하드링크된 파일을 복사본으로 취급하기 때문에 사실상 매번 모든 파일을 다 복사하는 꼴이 된다.
  9. andromedarabbit revised this gist Aug 2, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion backup-to-gdfs.sh
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ fi

    type pigz || brew install pigz
    type rsync || brew install rsync
    type rsync-time-backup
    type rsync-time-backup.sh

    # Backup
    # rsync_tmbackup.sh는 hardlink를 활용하는데 Google File Stream에선 하드링크된 파일을 복사본으로 취급하기 때문에 사실상 매번 모든 파일을 다 복사하는 꼴이 된다.
  10. andromedarabbit revised this gist Aug 2, 2018. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions backup-to-gdfs.sh
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,10 @@ if [ -n "${SKIP_BACKUPS}" ]; then
    exit 0
    fi

    type pigz || brew install pigz
    type rsync || brew install rsync
    type rsync-time-backup

    # Backup
    # rsync_tmbackup.sh는 hardlink를 활용하는데 Google File Stream에선 하드링크된 파일을 복사본으로 취급하기 때문에 사실상 매번 모든 파일을 다 복사하는 꼴이 된다.
    SRC_DIRS=(
  11. andromedarabbit created this gist Aug 2, 2018.
    61 changes: 61 additions & 0 deletions backup-to-gdfs.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,61 @@
    #!/bin/bash
    if [ -n "${SKIP_BACKUPS}" ]; then
    exit 0
    fi

    # Backup
    # rsync_tmbackup.sh는 hardlink를 활용하는데 Google File Stream에선 하드링크된 파일을 복사본으로 취급하기 때문에 사실상 매번 모든 파일을 다 복사하는 꼴이 된다.
    SRC_DIRS=(
    "${HOME}/dotfiles"
    )

    for ix in ${!SRC_DIRS[*]}
    do
    SRC_DIR=${SRC_DIRS[$ix]}
    BASENAME="$(basename ${SRC_DIR})"
    TARGET_DIR="/Volumes/GoogleDrive/My Drive/백업/Snapshots"
    mkdir -p -- "${TARGET_DIR}"
    touch "${TARGET_DIR}/backup.marker"
    echo rsync_tmbackup.sh "${HOME}/${BASENAME}" "${TARGET_DIR}" "${THIS_DIR}/rsync-exclude-patterns.txt"
    done

    SRC_DIRS=(
    "${HOME}/Movies"
    "${HOME}/Music"
    "${HOME}/Downloads"
    "${HOME}/Desktop"
    )

    for ix in ${!SRC_DIRS[*]}
    do
    SRC_DIR=${SRC_DIRS[$ix]}
    BASENAME="$(basename ${SRC_DIR})"
    TARGET_DIR="/Volumes/GoogleDrive/My Drive/백업/Snapshots"
    BACKUP_DIR="/Volumes/GoogleDrive/My Drive/백업/Backups/${BASENAME}$(date +\%Y-\%m-\%d)"
    rsync -av -delete --backup --backup-dir="${BACKUP_DIR}" "${SRC_DIR}" "${TARGET_DIR}" --exclude-from "${THIS_DIR}/rsync-exclude-patterns.txt"
    done

    # 용량이 작은 텍스트 파일이 많은 경우에는 작업 폴더 전체를 압축해서 백업하는 편이 시간이 덜 걸린다. 병렬 압축을 지원하는 pigz 같은 도구를 이용하면 파일 숫자가 많아도 걱정할 필요가 없다.
    # See https://www.reddit.com/r/linux/comments/3cnn54/just_a_reminder_on_multi_core_systems_use_pigz/
    SRC_DIRS=(
    "${HOME}/Documents"
    )

    for ix in ${!SRC_DIRS[*]}
    do
    SRC_DIR=${SRC_DIRS[$ix]}
    BASENAME="$(basename ${SRC_DIR})"
    TARGET_DIR="/Volumes/GoogleDrive/My Drive/백업/${BASENAME}"
    TARGET_FILENAME="$(date +%Y-%m-%d).tar.gz"

    # Processor 중 절반만 동원한다.
    THREADS=$[ $(nproc --all) / 2 ]

    mkdir -p "${TARGET_DIR}"

    pushd "$(dirname ${SRC_DIR})Sublime/"
    tar -c "${BASENAME}" | pigz --fast -p ${THREADS} -c | split -a 5 -d -b "3000M" - "${TARGET_DIR}/${TARGET_FILENAME}"
    popd

    find "${TARGET_DIR}" -mtime +30 -type f -delete
    done