This directory contains various scripts for automating tasks, maintenance, and operations related to the Bitrix infrastructure.
For Python scripts in this directory, it's recommended to use a virtual environment:
# Create virtual environment
python3 -m venv venv
# Activate virtual environment
source venv/bin/activate
# Install required packages
pip3 install -r requirements.txtBelow is a list of scripts and relevant files found in this directory:
-
check-404.sh- Type: Shell script (
.sh) - Purpose: Analyzes nginx logs to find 404 errors from search engine bots for redirect troubleshooting.
- Notes: Might use
urls.txtor a similar file as input.
- Type: Shell script (
-
compare-backups.sh- Type: Shell script (
.sh) - Purpose: Interactive tool to compare two backups from S3, showing differences between selected dates.
- Type: Shell script (
-
disaster-recovery.sh- Type: Shell script (
.sh) - Purpose: Automates disaster recovery process by setting up a fresh Ubuntu server with Docker, restoring files from S3 backup, and recovering MySQL database.
- Notes: Critical script that orchestrates multiple recovery steps.
- Type: Shell script (
-
file-backup.sh- Type: Shell script (
.sh) - Purpose: Performs incremental file backups to S3 using duplicity. Excludes cache, logs, and development directories. Full backup every 60 days.
- Type: Shell script (
-
find-image-type-mismatch.sh- Type: Shell script (
.sh) - Purpose: Detects images where file extension doesn't match actual MIME type.
- Type: Shell script (
-
fix-rights.sh- Type: Shell script (
.sh) - Purpose: Sets proper file ownership for containers (UID/GID 1000 for PHP/Nginx, 1001 for MySQL). Must be run after file operations.
- Notes: Critical for ensuring the application runs correctly after deployment or file changes.
- Type: Shell script (
-
mysql-dump.sh- Type: Shell script (
.sh) - Purpose: Creates compressed MySQL dump and uploads to S3. Excludes user sessions table to reduce backup size.
- Notes: May require database credentials, possibly from environment variables or a configuration file.
- Type: Shell script (
-
optimise-images.sh- Type: Shell script (
.sh) - Purpose: Optimizes PNG, JPEG, WebP, and GIF images using various tools. Uses SQLite database at
private/image-optimisation/optimised.dbto track processed files and avoid reprocessing.
- Type: Shell script (
-
renew-dev.sh- Type: Shell script (
.sh) - Purpose: Recreates dev site from production or from an existing backup.
- Options:
--date- Restore from an existing backup file instead of creating a new dump from production. When used, the script will:- List available backup dates from
/web/backup/(newest first, up to 20) - Prompt for date selection (YYYY-MM-DD format)
- List available
.sql.gzfiles for that date - Prompt for file selection
- Restore from the selected backup
- List available backup dates from
- Use cases:
- Restore dev from a specific point in time for debugging
- Compare current prod data with historical backup (useful with SEO tools)
- Test migrations against old data
- Type: Shell script (
-
requirements.txt- Type: Data file (Python dependencies)
- Purpose: Lists Python package dependencies required by Python scripts in this directory (e.g.,
urls.py). - Notes: Used with
pip install -r requirements.txt.
-
setup.py- Type: Python packaging script (
.py) - Purpose: Standard Python project setup script, likely used for packaging any Python utilities or scripts in this directory if they were to be distributed or installed as a package.
- Type: Python packaging script (
-
phpstan-scan.sh- Type: Shell script (
.sh) - Purpose: Weekly PHPStan static-analysis scan of the prod Bitrix tree; writes the owned-code error count to
logs/phpstan/owned_errors_count.txtfor Zabbix to read viasystem.run. Self-updates the PHPStan PHAR on each run. - Notes: See the PHPStan static analysis monitoring section in the main Readme for setup instructions, Zabbix template import, and the two scan scopes (owned vs diagnostic).
- Type: Shell script (
-
seo-reindex.sh- Type: Shell script (
.sh) - Purpose: Drains
/web/private/seo-reindex/queue.txtinto the Yandex Webmaster recrawl API, up to the account-wide daily quota (~960 URLs/day). Runs daily at 00:15 MSK as theadminuser. - Notes: Requires
private/environment/seo-reindex.envwith a valid Yandex Webmaster OAuth token. Logs go tologs/seo-reindex/YYYY-MM-DD.log. Bing reindexing is handled separately viabin/search-reindex submit --bing-only.
- Type: Shell script (
-
update-dns-token.sh- Type: Shell script (
.sh) - Purpose: Updates Yandex Cloud DNS authentication token for automatic certificate renewal.
- Notes: Requires API credentials, probably sourced from environment variables or a secure configuration file.
- Type: Shell script (
-
urls.py- Type: Python script (
.py) - Purpose: Python utility for checking URLs, finding redirects, broken links, and extracting page titles. Supports updating redirect maps.
- Notes: May use
requirements.txtfor its dependencies.
- Type: Python script (
Read-only MySQL CLI via SSH socket tunnel, using the claude_ro user with SELECT-only privileges. Designed for safe database access from AI agents (e.g. Claude Code) and ad-hoc queries.
Prerequisites:
mycliinstalled (brew install myclion macOS)- SSH access to the server configured
Setup:
-
Add SSH host alias to
~/.ssh/config:Host bitrix HostName your-server.example.com User your-username IdentityFile ~/.ssh/your-key -
Add
MYSQL_CLAUDE_RO_PASSWORDto server's/web/private/environment/mysql.env -
Create the MySQL user on the server:
CREATE USER 'claude_ro'@'localhost' IDENTIFIED BY 'password_from_env'; GRANT SELECT ON favor_group_ru.* TO 'claude_ro'@'localhost'; GRANT SELECT ON dev_favor_group_ru.* TO 'claude_ro'@'localhost'; FLUSH PRIVILEGES;
-
Add to your shell profile:
export PATH="/path/to/bitrix.infra/bin:$PATH" export SSH_HOST="bitrix" # optional, defaults to "bitrix"
Usage:
fgmysql # Interactive session (production)
fgmysql -e "SELECT ..." # Run query and exit
fgmysql dev # Connect to dev database
fgmysql dev -e "SELECT ..." # Query dev databaseThe tunnel starts automatically and password is fetched from the server (cached for 1 hour).
Manual tunnel management:
./mysql-tunnel.sh start # Start tunnel
./mysql-tunnel.sh status # Check status
./mysql-tunnel.sh stop # Stop tunnelSubmits URLs to Yandex and Bing for reindexing. Useful after content updates, fixing 404 errors, or adding new pages.
Setup:
-
Add
bin/to your PATH:export PATH="/path/to/bitrix.infra/bin:$PATH"
-
Run interactive setup (guides you through Yandex OAuth app creation and optional Bing API key):
search-reindex setup
The script auto-detects host IDs for favor-group.ru sites. Yandex uses OAuth (oauth.yandex.ru), Bing uses a simple API key from Bing Webmaster Tools. Config is stored in bin/.search-reindex (gitignored).
Usage:
search-reindex list # List verified Yandex hosts
search-reindex quota # Show remaining Yandex daily quota
search-reindex submit-url [--bing-only] <url>... # Submit one or more URLs
search-reindex submit [--bing-only] <file> # Submit URLs from file
search-reindex submit-regions [--bing-only] <file> # Submit URLs for MSK, SPB, TULA
search-reindex diagnostics # Check Yandex site issues--bing-only skips Yandex submission (e.g. when its daily quota is exhausted but Bing's separate quota still has headroom).
Examples:
# Submit specific URLs for reindexing (goes to both Yandex and Bing)
search-reindex submit-url https://favor-group.ru/catalog/profnastil/1484/
# Submit URLs from file for all regional subdomains
search-reindex submit-regions /tmp/urls.txt
# Read relative URLs from stdin
echo "/catalog/new-page/" | search-reindex submit-regions -
# Push to Bing only (e.g. Yandex quota already drained)
search-reindex submit --bing-only /tmp/urls.txt
# Check for site issues (exit 1 if FATAL/CRITICAL — Zabbix-friendly)
search-reindex diagnostics && echo 'All OK'Routine reindexing via the server-side cron: for bulk Yandex submissions that exceed the ~960/day quota, append absolute URLs to /web/private/seo-reindex/queue.txt on the server. The seo-reindex.sh cron (00:15 MSK daily, runs as admin) drains the queue top-down up to remaining quota and removes attempted lines. Bing has a separate 10 000/day quota and is sent manually with --bing-only from a workstation.
Moved to the private overlay repository (bin/yandex-reviews there): the organisation IDs and Bitrix iblock bindings are site-specific.