Learn about Centmin Mod LEMP Stack today
Become a Member

Sysadmin Directory Backup

Discussion in 'System Administration' started by Itworx4me, Feb 9, 2025.

  1. Itworx4me

    Itworx4me Premium Member Premium Member

    339
    35
    28
    Mar 14, 2017
    Ratings:
    +65
    Local Time:
    4:56 AM
    Nginx 1.27.4
    MariaDB 10.6.21
    Would this be the correct way to backup a directory?

    Code (Text):
    tar -czf archive.name.tar.gz /home/nginx/domains/mydomain.com/public


    Thanks,
    Itworx4me

     
  2. eva2000

    eva2000 Administrator Staff Member

    58,895
    12,490
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +19,122
    Local Time:
    9:56 PM
    Nginx 1.31.x
    MariaDB 10.x/11.4+/12.3+
    Code (Text):
    tar -czpf archive.name.tar.gz -C /home/nginx/domains/mydomain.com public

    • tar → Calls the tar utility.
    • -c → Creates a new archive.
    • -z → Compresses the archive using gzip.
    • -p → Preserves file permissions.
    • -f archive.name.tar.gz → Specifies the archive filename.
    • -C /home/nginx/domains/mydomain.com → Changes the working directory to /home/nginx/domains/mydomain.com before archiving.
    • public → The relative path of the folder being archived.
    To restore the archive back to /home/nginx/domains/mydomain.com/, run:
    Code (Text):
    tar -xzpf archive.name.tar.gz -C /home/nginx/domains/mydomain.com

    This will restore the public/ directory inside /home/nginx/domains/mydomain.com/, keeping its structure and permissions intact. If you want to restore to a staging directory first, change the path for -C flag
     
  3. Itworx4me

    Itworx4me Premium Member Premium Member

    339
    35
    28
    Mar 14, 2017
    Ratings:
    +65
    Local Time:
    4:56 AM
    Nginx 1.27.4
    MariaDB 10.6.21
    Thank you. Much appreciated