You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

51 lines
1.5 KiB

  1. #!/bin/bash
  2. # Move uploaded .warc.gz files to an archive directory.
  3. # When the archive is large enough, make a tar and start with a
  4. # new archive.
  5. #
  6. # Be careful: this script assumes that any file in the upload directory
  7. # that has a name that ends with *.warc.gz is a fully uploaded file and
  8. # can be moved somewhere else. Remember this when running Rsync.
  9. #
  10. INCOMING_UPLOADS_DIR=$1 # /home/archiveteam/uploads
  11. CHUNKER_WORKING_DIR=$2 # /home/archiveteam/processed
  12. PACKING_QUEUE_DIR="$CHUNKER_WORKING_DIR/archive"
  13. MEGABYTES_PER_CHUNK=$((1024*25))
  14. # if not specified in command-line arguments
  15. if [ -z $INCOMING_UPLOADS_DIR ]
  16. then
  17. source ./config.sh || exit 1
  18. fi
  19. mkdir -p "$CHUNKER_WORKING_DIR" || exit 1
  20. mkdir -p "$PACKING_QUEUE_DIR" || exit 1
  21. # find every .warc.gz in the upload directory
  22. find "$INCOMING_UPLOADS_DIR" -type f -name "*.warc.gz" \
  23. | while read filename
  24. do
  25. # skip partial uploads
  26. if [[ $filename =~ rsync-tmp ]]
  27. then
  28. continue
  29. fi
  30. # move to the current/ directory
  31. echo "Moving ${filename}"
  32. mkdir -p "$CHUNKER_WORKING_DIR/current"
  33. mv "${filename}" "$CHUNKER_WORKING_DIR/current/"
  34. # if the current/ directory is large enough,
  35. # rename it to archive-XXXXX and start a new current/
  36. cur_size=$( du -BM -s "$CHUNKER_WORKING_DIR/current" | grep -oE "^[0-9]+" )
  37. if [[ $cur_size -gt $MEGABYTES_PER_CHUNK ]]
  38. then
  39. timestamp=$( date +'%Y%m%d%H%M%S' )
  40. echo "Current archive is full, moving to ${timestamp}."
  41. mv "$CHUNKER_WORKING_DIR/current" "$PACKING_QUEUE_DIR/${timestamp}"
  42. fi
  43. done