Common Operations
This section covers day-to-day mirror management tasks you’ll perform regularly: scheduling automated syncs, managing snapshots, monitoring mirror health, and troubleshooting common issues.
Scheduling Automatic Syncs
Mirrors need regular updates to stay current. Use cron to schedule automated syncs.
Using Cron
Create a cron job to sync daily at 2 AM:
sudo crontab -eAdd the following line:
0 2 * * * /usr/local/bin/mirrorctl sync >> /var/log/mirrorctl/sync.log 2>&1This runs mirrorctl sync daily at 2:00 AM and logs output to /var/log/mirrorctl/sync.log.
Create the log directory:
sudo mkdir -p /var/log/mirrorctlDifferent Sync Schedules for Different Mirrors
You can sync mirrors on different schedules:
# Sync security updates every 4 hours (critical)
0 */4 * * * /usr/local/bin/mirrorctl sync ubuntu-security >> /var/log/mirrorctl/security.log 2>&1
# Sync main repository daily at 2 AM
0 2 * * * /usr/local/bin/mirrorctl sync ubuntu >> /var/log/mirrorctl/ubuntu.log 2>&1
# Sync development repository weekly on Sunday at 3 AM
0 3 * * 0 /usr/local/bin/mirrorctl sync ubuntu-proposed >> /var/log/mirrorctl/proposed.log 2>&1This prioritizes security updates while reducing bandwidth usage for less critical mirrors.
Using Systemd Timers
For systemd-based systems, create a timer for more control:
Create /etc/systemd/system/mirrorctl-sync.service:
[Unit]
Description=Mirrorctl Repository Sync
After=network-online.target
Wants=network-online.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/mirrorctl sync
StandardOutput=journal
StandardError=journalCreate /etc/systemd/system/mirrorctl-sync.timer:
[Unit]
Description=Run mirrorctl sync daily
Requires=mirrorctl-sync.service
[Timer]
OnCalendar=daily
OnCalendar=02:00
Persistent=true
[Install]
WantedBy=timers.targetEnable and start the timer:
sudo systemctl daemon-reload
sudo systemctl enable mirrorctl-sync.timer
sudo systemctl start mirrorctl-sync.timerCheck timer status:
sudo systemctl status mirrorctl-sync.timer
sudo systemctl list-timers mirrorctl-sync.timerView sync logs:
sudo journalctl -u mirrorctl-sync.service -fManaging Snapshots
List All Snapshots
View snapshots for a specific mirror:
mirrorctl snapshot list ubuntu-nobleView all snapshots for all mirrors:
mirrorctl snapshot listCreate Manual Snapshots
Create a snapshot before making configuration changes:
mirrorctl snapshot create ubuntu-noble "before-config-change"Create a snapshot of all mirrors:
for mirror in ubuntu ubuntu-security ubuntu-updates; do
mirrorctl snapshot create "$mirror" "2025-q1-baseline"
donePrune Old Snapshots
Manually apply retention policy:
mirrorctl snapshot prune ubuntu-noblePrune all mirrors:
for mirror in ubuntu ubuntu-security ubuntu-updates; do
mirrorctl snapshot prune "$mirror"
doneDelete Specific Snapshots
Remove a specific snapshot:
mirrorctl snapshot delete ubuntu-noble "2025-10-01T09-30-00Z"Monitoring Mirror Health
Check Sync Status
After a scheduled sync, verify it succeeded:
# For cron jobs
tail -50 /var/log/mirrorctl/sync.log
# For systemd
sudo journalctl -u mirrorctl-sync.service --since "today"Look for:
Sync completed successfullymessages- PGP signature verification success
- No error or warning messages
Monitor Disk Space
Repository mirrors consume significant disk space. Monitor regularly:
# Check mirror disk usage
du -sh /var/www/apt/*
# Check snapshot disk usage
du -sh /var/lib/mirrorctl/snapshots/*/*
# Check available space
df -h /var/www/apt/Set up automated alerts when disk usage exceeds 80%:
#!/bin/bash
# Save as /usr/local/bin/check-mirror-disk.sh
THRESHOLD=80
USAGE=$(df /var/www/apt/ | tail -1 | awk '{print $5}' | sed 's/%//')
if [ "$USAGE" -gt "$THRESHOLD" ]; then
echo "WARNING: Mirror disk usage at ${USAGE}%" | \
mail -s "Mirror Disk Space Alert" [email protected]
fiSchedule it in cron:
0 */6 * * * /usr/local/bin/check-mirror-disk.shMonitor Sync Timing
Track how long syncs take:
# View sync duration from logs
grep "Duration:" /var/log/mirrorctl/sync.log | tail -5Increasing sync times may indicate:
- Growing repository size
- Network bandwidth issues
- Disk I/O problems
Verify Mirror Integrity
Periodically verify your mirror serves correct content:
# Test Release file accessibility
curl -I http://your-mirror-server/ubuntu-noble/current/dists/noble/Release
# Verify Release file signature (if you have the key)
gpg --verify \
/var/www/apt/ubuntu-noble/current/dists/noble/Release.gpg \
/var/www/apt/ubuntu-noble/current/dists/noble/Release
# Test package download
apt download --print-uris curl | grep http://your-mirror-serverTroubleshooting Common Issues
Sync Failures
If syncs fail, check:
-
Network connectivity:
curl -I https://archive.ubuntu.com/ubuntu/ -
DNS resolution:
nslookup archive.ubuntu.com -
Disk space:
df -h /var/www/apt/ -
Configuration validity:
mirrorctl check config -
Detailed error output:
sudo mirrorctl sync --verbose-errors
PGP Verification Failures
If PGP verification fails:
-
Verify key file exists:
ls -l /etc/mirrorctl/keys/ubuntu-archive-keyring.gpg -
Check key fingerprint:
gpg --show-keys /etc/mirrorctl/keys/ubuntu-archive-keyring.gpg -
Test manual verification:
gpg --verify \ /var/www/apt/ubuntu-noble/dists/noble/Release.gpg \ /var/www/apt/ubuntu-noble/dists/noble/Release -
Update signing keys (keys change periodically):
sudo gpg --keyserver keyserver.ubuntu.com \ --recv-keys 0x871920D1991BC93C \ --export > /etc/mirrorctl/keys/ubuntu-archive-keyring.gpg
Slow Syncs
If syncs are taking too long:
- Use a closer upstream mirror: Change
urlto a geographically closer mirror - Check network bandwidth:
iftopornloadduring sync - Reduce mirror scope: Fewer architectures/sections if possible
- Check disk I/O:
iostat -x 5during sync - Consider parallel downloads: Future mirrorctl feature
Disk Space Issues
If you’re running out of space:
-
Prune old snapshots:
mirrorctl snapshot prune --keep-last 3 ubuntu-noble -
Reduce
keep_lastin config:[snapshot.prune] keep_last = 3 # Reduced from 5 -
Use package filters:
[mirrors.ubuntu-noble.filters] keep_versions = 2 exclude_patterns = [".*-dbg$", ".*-doc$"] -
Remove unnecessary architectures/sections:
architectures = ["amd64"] # Remove arm64 if not needed sections = ["main"] # Remove universe if not needed
Corrupted Mirror State
If the mirror state becomes corrupted:
-
Run a fresh sync:
sudo mirrorctl sync ubuntu-noblemirrorctl will detect and re-download corrupted files.
-
Restore from snapshot:
# List snapshots to find a good one mirrorctl snapshot list ubuntu-noble # Publish the good snapshot to production mirrorctl snapshot publish ubuntu-noble "2025-10-14T09-30-00Z" -
In extreme cases, re-create the mirror:
# Backup config sudo cp /etc/mirrorctl/mirror.toml /etc/mirrorctl/mirror.toml.backup # Remove corrupted mirror sudo rm -rf /var/www/apt/ubuntu-noble # Resync sudo mirrorctl sync ubuntu-noble
Updating Configuration
When updating mirror configuration:
-
Test configuration validity:
sudo mirrorctl check config -
Create a snapshot first (if config changes might affect content):
mirrorctl snapshot create ubuntu-noble "before-config-update" -
Test with dry-run:
sudo mirrorctl sync --dry-run -
Apply the change:
sudo mirrorctl sync -
Verify the update:
mirrorctl snapshot list ubuntu-noble ls -la /var/www/apt/ubuntu-noble/
Log Management
Over time, logs can consume significant space. Rotate them:
Create /etc/logrotate.d/mirrorctl:
/var/log/mirrorctl/*.log {
daily
rotate 14
compress
delaycompress
missingok
notifempty
create 0640 root root
}Test logrotate:
sudo logrotate -d /etc/logrotate.d/mirrorctl
sudo logrotate -f /etc/logrotate.d/mirrorctlMonitoring with Systemd
If using systemd timers, monitor with:
# Check last sync status
sudo systemctl status mirrorctl-sync.service
# View recent logs
sudo journalctl -u mirrorctl-sync.service -n 50
# Follow logs in real-time
sudo journalctl -u mirrorctl-sync.service -f
# Check timer schedule
sudo systemctl list-timers mirrorctl-sync.timerPerformance Tips
- Schedule syncs during off-peak hours to reduce impact on network
- Use local/nearby upstream mirrors to reduce latency
- Monitor and tune snapshot retention to balance safety and disk usage
- Use SSD storage for better I/O performance during syncs
- Ensure sufficient RAM for caching during large syncs
What’s Next?
You’ve learned the essential operations for managing mirrorctl. Check out Next Steps to explore advanced topics and additional resources.