Skip to content

Commit

Permalink
maintenance scripts (#1627)
Browse files Browse the repository at this point in the history
* some helpful scripts for production deployments

* rsync cron

* change sync to every minute
  • Loading branch information
brenzi authored Nov 4, 2024
1 parent c0a9768 commit 10fffb6
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 0 deletions.
38 changes: 38 additions & 0 deletions scripts/archive-yesterdays-logs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
# a script to compress enclave extrinsic logs in the working dir for the previous day and delete them to clean up
# run as root with crontab
# crontab -e
# 0 2 * * * /path/to/your_script.sh /abs-path-to-log-directory

# Check if a directory argument was provided, default to current directory if not
DIRECTORY="${1:-.}"
# Remove any trailing slash from the directory path
DIRECTORY="${DIRECTORY%/}"

# Define the archive file name with yesterday's date
ARCHIVE_NAME="archive_$(date -d 'yesterday' +%Y%m%d).tar.gz"
# Define the date string for yesterday
YESTERDAY_DATE=$(date -d 'yesterday' +%Y%m%d)

# Find and archive all files in the directory created yesterday
#FILES_TO_ARCHIVE=$(find "$DIRECTORY" -type f -newermt "yesterday 00:00:00" ! -newermt "today 00:00:00")
# Find all files in the directory matching yesterday's date in the filename
FILES_TO_ARCHIVE=$(find "$DIRECTORY" -type f -name "extrinsics-$YESTERDAY_DATE-*")

# Check if there are any files to archive
if [ -z "$FILES_TO_ARCHIVE" ]; then
echo "No files created yesterday in $DIRECTORY."
exit 0
fi

# Create the archive with the files found
tar -czf "$DIRECTORY/$ARCHIVE_NAME" $FILES_TO_ARCHIVE

# Check if the tar command was successful
if [ $? -eq 0 ]; then
# If successful, delete the original files
echo "Archive created successfully as $ARCHIVE_NAME. Deleting original files."
rm -f $FILES_TO_ARCHIVE
else
echo "Failed to create archive. Original files are not deleted."
fi
17 changes: 17 additions & 0 deletions scripts/crontab.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# as root, execute
# crontab -e
# and make the following entries:

# daily @2:00am, archive logs and clean up
0 2 * * * /opt/sidechain-paseo/archive-yesterdays-logs.sh /opt/sidechain-paseo/log-extrinsics-to-Integritee
0 2 * * * /opt/sidechain-paseo/archive-yesterdays-logs.sh /opt/sidechain-paseo/log-extrinsics-to-TargetA

# daily @1:00am, snapshot light client dB's (syncing is fast enough for 24h intervals)
0 1 * * * /opt/sidechain-paseo/snapshot-integritee-db.sh /opt/sidechain-paseo
0 1 * * * /opt/sidechain-paseo/snapshot-target-a-db.sh /opt/sidechain-paseo

# hourly, take shard snapshot
0 * * * * /opt/sidechain-paseo/snapshot-shards.sh /opt/sidechain-paseo

# every minute, rsync to peer node which might be able to hot-swap in emergencies. execute as user, not root
* * * * * su - ubuntu -c "rsync -avz --delete /opt/sidechain-paseo/ ubuntu@integritee-2:/opt/mirror-integritee-1/sidechain-paseo/"
9 changes: 9 additions & 0 deletions scripts/snapshot-integritee-db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
# Check if a directory argument was provided, default to current directory if not
DIRECTORY="${1:-.}"
# Remove any trailing slash from the directory path
DIRECTORY="${DIRECTORY%/}"

timestamp=$(date +%Y%m%d-%T)
echo "snappshotting all light client db's at $timestamp"
cp -r "$DIRECTORY/integritee_lcdb" "$DIRECTORY/integritee_lcdb_$timestamp"
10 changes: 10 additions & 0 deletions scripts/snapshot-shards.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
# Check if a directory argument was provided, default to current directory if not
DIRECTORY="${1:-.}"
# Remove any trailing slash from the directory path
DIRECTORY="${DIRECTORY%/}"

timestamp=$(date +%Y%m%d-%T)
echo "snappshotting all shards at $timestamp"
cp -r "$DIRECTORY/shards" "$DIRECTORY/shards_$timestamp"
cp -r "$DIRECTORY/sidechain_db" "$DIRECTORY/sidechain_db_$timestamp"
9 changes: 9 additions & 0 deletions scripts/snapshot-target-a-db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
# Check if a directory argument was provided, default to current directory if not
DIRECTORY="${1:-.}"
# Remove any trailing slash from the directory path
DIRECTORY="${DIRECTORY%/}"

timestamp=$(date +%Y%m%d-%T)
echo "snappshotting all light client db's at $timestamp"
cp -r "$DIRECTORY/target_a_lcdb" "$DIRECTORY/target_a_lcdb_$timestamp"

0 comments on commit 10fffb6

Please sign in to comment.