-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
BOT_TOKEN=7672104553:AAH_RwwDpuJlMu9smaFjXQid7xJQVmfxVNs |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
name: Database Backup | ||
|
||
on: | ||
schedule: | ||
- cron: '0 0 * * *' # Run daily at midnight | ||
workflow_dispatch: # Allow manual trigger | ||
|
||
env: | ||
WORKING_DIRECTORY: backup | ||
|
||
jobs: | ||
backup: | ||
runs-on: ubuntu-22.04 | ||
|
||
steps: | ||
- name: Setup SSH | ||
uses: webfactory/ssh-agent@v0.9.0 | ||
with: | ||
ssh-private-key: '${{ secrets.SSH_PRIVATE_KEY }}' | ||
|
||
- name: Add SSH known hosts | ||
run: | | ||
mkdir -p ~/.ssh | ||
ssh-keyscan -H ${{ secrets.SERVER_IP }} >> ~/.ssh/known_hosts | ||
- name: Download database file | ||
run: | | ||
# Create directory with timestamp | ||
timestamp=$(date +%Y%m%d_%H%M%S) | ||
target_directory=$WORKING_DIRECTORY | ||
mkdir -p "$target_directory" || { | ||
echo "Failed to create directory $target_directory" | ||
exit 1 | ||
} | ||
timestamp=$(date +%Y%m%d_%H%M%S) | ||
echo "TIMESTAMP=$timestamp" >> $GITHUB_ENV | ||
mkdir -p "${{ env.WORKING_DIRECTORY }}" || { | ||
echo "Failed to create directory ${{ env.WORKING_DIRECTORY }}" | ||
exit 1 | ||
} | ||
# Download db files directly to timestamped directory | ||
rsync -avz ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_IP }}:~/bot/*.db "${{ env.WORKING_DIRECTORY }}" | ||
- name: Upload backup | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: database-backup-${{ env.TIMESTAMP }} | ||
path: ${{ env.WORKING_DIRECTORY }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
name: Deploy Bot On Server | ||
|
||
on: | ||
release: | ||
types: | ||
- published | ||
workflow_dispatch: # Allow manual trigger | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
environment: production # Added for better secrets management | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup SSH | ||
uses: webfactory/ssh-agent@v0.9.0 | ||
with: | ||
ssh-private-key: '${{ secrets.SSH_PRIVATE_KEY }}' | ||
|
||
- name: Add SSH known hosts | ||
run: | | ||
mkdir -p ~/.ssh | ||
ssh-keyscan -H ${{ secrets.SERVER_IP }} >> ~/.ssh/known_hosts | ||
- name: Create env file | ||
run: | | ||
echo "BOT_TOKEN=${{ secrets.BOT_TOKEN }}" > .env | ||
- name: Create backup directory | ||
run: | | ||
ssh ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_IP }} ' | ||
timestamp=$(date +%Y%m%d_%H%M%S) | ||
if [ -d ~/bot ]; then | ||
rsync -av --progress --exclude="__pycache__/" \ | ||
--exclude="env/" \ | ||
~/bot/ ~/bot_backup_$timestamp && echo "Backup done" || echo "Backup failed" | ||
else | ||
echo "No need to backup!" | ||
fi | ||
' | ||
- name: Transfer files to server | ||
run: | | ||
rsync -avz --exclude '.git*' \ | ||
--exclude '.idea/' \ | ||
./ ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_IP }}:~/bot/ | ||
- name: Deploy and verify | ||
run: | | ||
ssh ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_IP }} ' | ||
cd ~/bot || exit 1 | ||
# Ensure deploy.sh exists and is executable | ||
if [ ! -f "deploy.sh" ]; then | ||
echo "Error: deploy.sh not found!" | ||
exit 1 | ||
fi | ||
# Set permissions | ||
chmod +x deploy.sh | ||
# Run deploy script with error handling | ||
if sudo ./deploy.sh; then | ||
echo "Deployment completed successfully at $(date)" | ||
else | ||
echo "Deployment failed" | ||
# Optional: Restore from backup | ||
# latest_backup=$(ls -td ~/bot_backup_* | head -n1) | ||
# cp -r $latest_backup/* ~/bot/ | ||
exit 1 | ||
fi | ||
' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
alerts.db | ||
.env |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.