|
|
#!/bin/bash |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
REPO_DIR="/data/adaptai/platform/signalcore" |
|
|
LOG_FILE="/data/adaptai/platform/signalcore/backup.log" |
|
|
MAX_LOG_SIZE=10485760 |
|
|
|
|
|
|
|
|
GREEN='\033[0;32m' |
|
|
YELLOW='\033[1;33m' |
|
|
RED='\033[0;31m' |
|
|
NC='\033[0m' |
|
|
|
|
|
|
|
|
log() { |
|
|
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" | tee -a "$LOG_FILE" |
|
|
} |
|
|
|
|
|
|
|
|
error() { |
|
|
echo "$(date '+%Y-%m-%d %H:%M:%S') - ERROR: $1" | tee -a "$LOG_FILE" |
|
|
exit 1 |
|
|
} |
|
|
|
|
|
|
|
|
rotate_log() { |
|
|
if [ -f "$LOG_FILE" ] && [ $(stat -c%s "$LOG_FILE") -gt $MAX_LOG_SIZE ]; then |
|
|
mv "$LOG_FILE" "${LOG_FILE}.$(date +%Y%m%d_%H%M%S)" |
|
|
log "Rotated log file" |
|
|
fi |
|
|
} |
|
|
|
|
|
|
|
|
backup_repository() { |
|
|
cd "$REPO_DIR" || error "Cannot change to repository directory" |
|
|
|
|
|
log "Starting automated backup of SignalCore repository..." |
|
|
|
|
|
|
|
|
if git diff --quiet && git diff --staged --quiet; then |
|
|
log "${YELLOW}No changes to commit${NC}" |
|
|
return 0 |
|
|
fi |
|
|
|
|
|
|
|
|
git add . || error "Failed to add changes" |
|
|
|
|
|
|
|
|
COMMIT_MESSAGE="Auto-backup: $(date '+%Y-%m-%d %H:%M:%S') - SignalCore work" |
|
|
git commit -m "$COMMIT_MESSAGE" || error "Failed to commit changes" |
|
|
|
|
|
|
|
|
git push origin main || error "Failed to push main branch" |
|
|
git push origin development || error "Failed to push development branch" |
|
|
|
|
|
log "${GREEN}Backup completed successfully${NC}" |
|
|
log "Changes committed and pushed to GitHub" |
|
|
|
|
|
|
|
|
git status --short | head -10 | while read line; do |
|
|
log " $line" |
|
|
done |
|
|
} |
|
|
|
|
|
|
|
|
main() { |
|
|
rotate_log |
|
|
log "=== Starting SignalCore Backup ===" |
|
|
|
|
|
|
|
|
if ! command -v git &> /dev/null; then |
|
|
error "Git is not available" |
|
|
fi |
|
|
|
|
|
|
|
|
if ! git rev-parse --git-dir > /dev/null 2>&1; then |
|
|
error "Not in a git repository" |
|
|
fi |
|
|
|
|
|
|
|
|
backup_repository |
|
|
|
|
|
log "=== Backup Completed ===" |
|
|
echo "" >> "$LOG_FILE" |
|
|
} |
|
|
|
|
|
|
|
|
main "$@" |