Skip to content

Instantly share code, notes, and snippets.

@agostof
Last active July 25, 2024 16:28
Show Gist options
  • Save agostof/6d5a845b415a9357eb1774083096293e to your computer and use it in GitHub Desktop.
Save agostof/6d5a845b415a9357eb1774083096293e to your computer and use it in GitHub Desktop.
find_and_rsync_files_by_mod_time
# purpose: using the find utility to find files after a given modification time.
# This list could then be used to construct and rysync `--inclue-files-from` list.
find -mindepth 5 -type d -newermt 2023-09-14 -exec echo "{}" \; > ~/data_list_09142023_07242024.txt
# e.g.
#
# rsync -apuv --progress --include-from=rsync_include.txt user@host:/data_path/ data_path/
# note --include-from vs --files-from functionality
# building of the rsync list can be done with this or by adding the formatting +on find.
# e.g. Note there might be issues with relative paths
# INCLUDE_FILE=data_list_09142023_07242024_rsync_include.txt
# echo "+ */" > ${INCLUDE_FILE}
# find -mindepth 5 -type d -newermt 2023-09-14 -exec echo "+ {}" \; >> ${INCLUDE_FILE}
# echo "- *" >> ${INCLUDE_FILE}
LIST_FILE="data_list_09142023_07242024.txt"
INCLUDE_FILE="rsync_include.txt"
# Part 2: Prepare the rsync include file
echo "+ */" > "$INCLUDE_FILE"
while IFS= read -r relative_path; do
relative_path="${relative_path#./}"
echo "+ $relative_path/***" >> "$INCLUDE_FILE"
done < "$LIST_FILE"
echo "- *" >> "$INCLUDE_FILE"
# find manpage (https://man7.org/linux/man-pages/man1/find.1.html)
# Note that there is also `-anewer` `-cnewer` `-newer` `-mtime`.
# Some of these like -newer could be used with modification times
# relative to a specific file.
# using the newer flag is uses as follows
# -newerXY reference
# Compares the timestamp of the current file with reference. The
# reference argument is normally the name of a file (and one of
# its timestamps is used for the comparison) but it may also be a
# string describing an absolute time. X and Y are placeholders
# for other letters, and these letters select which time belonging
# to how reference is used for the comparison.
#
# a The access time of the file reference
# B The birth time of the file reference
# c The inode status change time of reference
# m The modification time of the file reference
# t reference is interpreted directly as a time
# More hints here:
# https://serverfault.com/questions/538767/how-to-rsync-files-folders-from-a-specific-date-forward
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment