Skip to content

Instantly share code, notes, and snippets.

@gdamjan
Last active March 21, 2025 17:47
Show Gist options
  • Save gdamjan/cc3a65cf9afa5fd7645c to your computer and use it in GitHub Desktop.
Save gdamjan/cc3a65cf9afa5fd7645c to your computer and use it in GitHub Desktop.

Revisions

  1. gdamjan revised this gist Dec 4, 2023. 2 changed files with 21 additions and 13 deletions.
    9 changes: 9 additions & 0 deletions archlinux-rsync-file-list.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    pool/packages
    core
    core-testing
    extra
    extra-testing
    multilib
    multilib-testing
    lastsync
    lastupdate
    25 changes: 12 additions & 13 deletions sync_arch_mirror.sh
    Original file line number Diff line number Diff line change
    @@ -1,25 +1,24 @@
    #! /bin/bash
    set -e
    set -euo pipefail

    REPO=rsync://ftp.acc.umu.se/mirror/archlinux/
    DEST=/home/arch/public_html/archlinux/
    if [ "$EUID" -eq 0 ]
    then echo "Don't run as root!"
    exit 1
    fi

    REPO=rsync://ftp.acc.umu.se/mirror/archlinux
    DEST=/srv/arch_mirror/archlinux
    RSYNC_FILE_LIST=/srv/arch_mirror/archlinux-rsync-file-list.txt

    mkdir -p $DEST

    # Common rsync options
    RSYNC_OPTS="-rtlH -4 --safe-links --no-motd --exclude=.*"
    : "${LAZY:="--delete-delay --delay-updates"}"
    RSYNC_OPTS="-rltH -4 --safe-links --no-motd $LAZY"

    # Only be verbose on tty
    if tty -s; then
    RSYNC_OPTS="$RSYNC_OPTS -v"
    fi

    # first get new package files (the pool) and don't delete anything
    /usr/bin/rsync $RSYNC_OPTS $REPO/pool/ $DEST/pool/

    # … and only then get the database, links and the structure
    /usr/bin/rsync $RSYNC_OPTS --delete-after --delay-updates $REPO $DEST \
    --exclude iso/ --exclude other/ --exclude archive/ --exclude sources/

    # --delete-before so that it frees disk space earlier
    /usr/bin/rsync $RSYNC_OPTS --delete-before $REPO/iso/ $DEST/iso/ --exclude archboot
    /usr/bin/rsync $RSYNC_OPTS --files-from=$RSYNC_FILE_LIST $REPO/ $DEST/
  2. gdamjan revised this gist May 18, 2018. 2 changed files with 3 additions and 1 deletion.
    2 changes: 1 addition & 1 deletion arch-mirror.service
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@ Description=Mirror arch linux

    [Service]
    Type=oneshot
    ExecStart=/home/arch/sync_arch_mirror.sh
    ExecStart=/usr/local/bin/sync_arch_mirror.sh
    User=arch
    IPAccounting=yes
    NoNewPrivileges=yes
    2 changes: 2 additions & 0 deletions sync_arch_mirror.sh
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,8 @@ set -e
    REPO=rsync://ftp.acc.umu.se/mirror/archlinux/
    DEST=/home/arch/public_html/archlinux/

    mkdir -p $DEST

    # Common rsync options
    RSYNC_OPTS="-rtlH -4 --safe-links --no-motd --exclude=.*"

  3. gdamjan revised this gist Oct 25, 2017. 1 changed file with 12 additions and 0 deletions.
    12 changes: 12 additions & 0 deletions arch-mirror.service
    Original file line number Diff line number Diff line change
    @@ -7,3 +7,15 @@ ExecStart=/home/arch/sync_arch_mirror.sh
    User=arch
    IPAccounting=yes
    NoNewPrivileges=yes
    PrivateTmp=yes
    PrivateDevices=yes
    ProtectSystem=strict
    ProtectControlGroups=yes
    ProtectKernelTunables=yes
    ProtectKernelModules=yes
    MemoryDenyWriteExecute=yes
    RestrictRealtime=yes
    RestrictNamespaces=yes
    RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
    SystemCallArchitectures=native
    LockPersonality=yes
  4. gdamjan revised this gist Oct 24, 2017. 2 changed files with 12 additions and 6 deletions.
    4 changes: 3 additions & 1 deletion arch-mirror.service
    Original file line number Diff line number Diff line change
    @@ -4,4 +4,6 @@ Description=Mirror arch linux
    [Service]
    Type=oneshot
    ExecStart=/home/arch/sync_arch_mirror.sh
    User=arch
    User=arch
    IPAccounting=yes
    NoNewPrivileges=yes
    14 changes: 9 additions & 5 deletions sync_arch_mirror.sh
    Original file line number Diff line number Diff line change
    @@ -1,19 +1,23 @@
    #! /bin/bash
    set -e

    REPO=rsync://mirror.de.leaseweb.net/archlinux/
    REPO=rsync://ftp.acc.umu.se/mirror/archlinux/
    DEST=/home/arch/public_html/archlinux/

    # Common rsync options
    RSYNC_OPTS="-rtlH -4 --safe-links --no-motd"
    RSYNC_OPTS="-rtlH -4 --safe-links --no-motd --exclude=.*"

    # Only be verbose on tty
    if tty -s; then
    RSYNC_OPTS="$RSYNC_OPTS -v"
    RSYNC_OPTS="$RSYNC_OPTS -v"
    fi

    # first get new package files (the pool)
    # first get new package files (the pool) and don't delete anything
    /usr/bin/rsync $RSYNC_OPTS $REPO/pool/ $DEST/pool/

    # … and only then get the database, links and the structure
    /usr/bin/rsync $RSYNC_OPTS --delete-after --delay-updates $REPO $DEST
    /usr/bin/rsync $RSYNC_OPTS --delete-after --delay-updates $REPO $DEST \
    --exclude iso/ --exclude other/ --exclude archive/ --exclude sources/

    # --delete-before so that it frees disk space earlier
    /usr/bin/rsync $RSYNC_OPTS --delete-before $REPO/iso/ $DEST/iso/ --exclude archboot
  5. gdamjan revised this gist Jul 25, 2015. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions sync_arch_mirror.sh
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    #! /bin/bash
    set -e

    REPO=rsync://mirror.de.leaseweb.net/archlinux/
    DEST=/home/arch/public_html/archlinux/

  6. gdamjan revised this gist Jul 25, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion sync_arch_mirror.sh
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@ REPO=rsync://mirror.de.leaseweb.net/archlinux/
    DEST=/home/arch/public_html/archlinux/

    # Common rsync options
    RSYNC_OPTS="-rtlH -4 --safe-links"
    RSYNC_OPTS="-rtlH -4 --safe-links --no-motd"

    # Only be verbose on tty
    if tty -s; then
  7. gdamjan revised this gist Jul 25, 2015. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions sync_arch_mirror.sh
    Original file line number Diff line number Diff line change
    @@ -14,6 +14,4 @@ fi
    /usr/bin/rsync $RSYNC_OPTS $REPO/pool/ $DEST/pool/

    # … and only then get the database, links and the structure
    /usr/bin/rsync $RSYNC_OPTS --delete-after --delay-updates $REPO $DEST

    date > /tmp/last.sync
    /usr/bin/rsync $RSYNC_OPTS --delete-after --delay-updates $REPO $DEST
  8. gdamjan revised this gist Jul 25, 2015. 2 changed files with 17 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions arch-mirror.service
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    [Unit]
    Description=Mirror arch linux

    [Service]
    Type=oneshot
    ExecStart=/home/arch/sync_arch_mirror.sh
    User=arch
    10 changes: 10 additions & 0 deletions arch-mirror.timer
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    [Unit]
    Description=Mirror arch almost every two hours

    [Timer]
    OnBootSec=15min
    OnUnitActiveSec=2h10m
    AccuracySec=10min

    [Install]
    WantedBy=timers.target
  9. gdamjan created this gist Jul 25, 2015.
    19 changes: 19 additions & 0 deletions sync_arch_mirror.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    #! /bin/bash
    REPO=rsync://mirror.de.leaseweb.net/archlinux/
    DEST=/home/arch/public_html/archlinux/

    # Common rsync options
    RSYNC_OPTS="-rtlH -4 --safe-links"

    # Only be verbose on tty
    if tty -s; then
    RSYNC_OPTS="$RSYNC_OPTS -v"
    fi

    # first get new package files (the pool)
    /usr/bin/rsync $RSYNC_OPTS $REPO/pool/ $DEST/pool/

    # … and only then get the database, links and the structure
    /usr/bin/rsync $RSYNC_OPTS --delete-after --delay-updates $REPO $DEST

    date > /tmp/last.sync