-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #54 from cytopia/ci-incremental-backup-checks
Validate incremental backups during CI
- Loading branch information
Showing
6 changed files
with
351 additions
and
12 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
set -u | ||
set -o pipefail | ||
|
||
|
||
# ------------------------------------------------------------------------------------------------- | ||
# PUBLIC FUNCTIONS | ||
# ------------------------------------------------------------------------------------------------- | ||
|
||
check_dir_size() { | ||
local src="${1}" | ||
local dst="${2}" | ||
|
||
src_size="$( get_dir_size_with_hardlinks "${src}" )" | ||
dst_size="$( get_dir_size_with_hardlinks "${dst}" )" | ||
|
||
if [ "${src_size}" -eq "${dst_size}" ]; then | ||
printf "[TEST] [OK] src-dir(%s) and dst-dir(%s) size match\\r\\n" "${src_size}" "${dst_size}" | ||
return 0 | ||
fi | ||
printf "[TEST] [FAIL] src-dir(%s) and dst-dir(%s) size don't match: (src: %s) (dst: %s)\\r\\n" "${src_size}" "${dst_size}" "${src}" "${dst}" | ||
exit 1 | ||
} | ||
|
||
|
||
# ------------------------------------------------------------------------------------------------- | ||
# PRIVATE FUNCTIONS | ||
# ------------------------------------------------------------------------------------------------- | ||
|
||
### | ||
### Return total size of directory in bytes. | ||
### It also counts the size of hardlinks. | ||
### | ||
### @param abs_path directory | ||
### | ||
get_dir_size_with_hardlinks() { | ||
local dir="${1}" | ||
local size= | ||
|
||
|
||
size="$( run "cd '${dir}' && du -d0 '.' | awk '{print \$1}'" "1" "stderr" )" | ||
echo "${size}" | ||
} | ||
|
||
### | ||
### Return total size of directory in bytes. | ||
### Subtract the size of any hardlinks. | ||
### | ||
### @param abs_path directory | ||
### | ||
get_dir_size_without_hardlinks() { | ||
local dir="${1}" | ||
local suffix="${2:-}" | ||
local actual_path= | ||
local current_dir_name= | ||
local parent_dir_path= | ||
local size= | ||
|
||
# Return the actual path (in case we're in a symlink) | ||
actual_path="$( run "cd '${dir}' && pwd -P" "1" "stderr" )" | ||
|
||
# Get only the name of the current directory | ||
current_dir_name="$( run "basename '${actual_path}'" "1" "stderr" )" | ||
|
||
# Get the parent directory path | ||
parent_dir_path="$( run "dirname '${actual_path}'" "1" "stderr" )" | ||
|
||
|
||
size="$( run "cd '${parent_dir_path}' && du -d2 2>/dev/null | grep -E '${current_dir_name}${suffix}\$' | head -1 | awk '{print \$1}'" "1" "stderr" )" | ||
echo "${size}" | ||
} |
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
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
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
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
Oops, something went wrong.