# **Azure Blob Sync Script - How To Use** This script syncs a directory to **Azure Blob Storage** using `azcopy` while: ✅ **Avoiding business hours** (default: 9 AM - 5 PM, configurable). ✅ **Preventing duplicate instances** (via a lock file). ✅ **Automatically resuming** unfinished jobs. ✅ **Logging progress & generating reports**. --- ## **📌 1. Script Usage** Run the script manually: ```bash ./run_azcopy.sh [log=true|false] [bandwidth_mbps] ``` ### **Example Commands** - **Basic sync with no bandwidth limit:** ```bash ./run_azcopy.sh /opt/AZURE/ false ``` - **Enable logging & limit bandwidth to 10 Mbps:** ```bash ./run_azcopy.sh /opt/AZURE/ true 10 ``` - **Run in the background & detach from terminal:** ```bash nohup ./run_azcopy.sh /opt/AZURE/ true 10 & disown ``` --- ## **⏲️ 2. Automating with Cron** Schedule the script to **run every hour**: ```bash crontab -e ``` Add this line: ```bash 0 * * * * /path/to/run_azcopy.sh /opt/AZURE/ true 10 ``` ### **How It Works** - Runs at **00 minutes past every hour** (e.g., 1:00, 2:00, 3:00, etc.). - If already running, the **next cron execution exits** to prevent duplicates. - If interrupted (e.g., business hours), the **next run resumes**. --- ## **🔍 3. Checking If the Script Is Running** Check if `azcopy` or the script is running: ```bash pgrep -fl run_azcopy.sh pgrep -fl azcopy ``` To **stop it manually**: ```bash pkill -f azcopy pkill -f run_azcopy.sh ``` --- ## **📄 4. Checking Logs & Reports** - **Sync Log (if enabled)**: ```bash tail -f azcopy_log_*.txt ``` - **Completion Report**: ```bash cat completion_report_*.txt ``` --- ## **⚙️ 5. Customizing Business Hours** Modify the script to change business hours: ```bash BUSINESS_HOURS_START=9 BUSINESS_HOURS_END=17 ``` --- ## **✅ 6. Expected Behavior** | Scenario | What Happens? | |----------|--------------| | **Cron runs script inside business hours** | Script exits immediately. | | **Script is running when cron starts again** | Second instance exits to prevent duplicates. | | **Sync job interrupted by business hours** | Next run resumes automatically. | | **Sync completes normally** | Report logs all transferred files. |