Get the most out of your Centmin Mod LEMP stack
Become a Member

Creating bash script to backup files from several directories

Discussion in 'System Administration' started by Sunka, Mar 5, 2016.

  1. Sunka

    Sunka Well-Known Member

    1,150
    325
    83
    Oct 31, 2015
    Pula, Croatia
    Ratings:
    +525
    Local Time:
    8:35 PM
    Nginx 1.17.9
    MariaDB 10.3.22
    Could someone help me to create bash script wich will be run with cron once every night.
    I want to put script in xxx folder, execute with cron and result should be in same folder.
    Script is going to copy several files from several different directories into xxx folder, gzip that files with date name for gzip and delete then that copied files and leave just gzip file with all that files in there. Also in script has to be included mtime command to delete gzip files older than 5 days (-mtime +3).

    Basically, I want to copy random conf and ini files, and gziped in one folder.
    I have full path for every file.

    Thanks

     
  2. eva2000

    eva2000 Administrator Staff Member

    55,189
    12,251
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,829
    Local Time:
    4:35 AM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    Might want to read some of the bash / shell related threads in this sub forum as there's a few tutorial threads including creating shell script discussions - see tag at bash | Centmin Mod Community
     
  3. Sunka

    Sunka Well-Known Member

    1,150
    325
    83
    Oct 31, 2015
    Pula, Croatia
    Ratings:
    +525
    Local Time:
    8:35 PM
    Nginx 1.17.9
    MariaDB 10.3.22
    I ended up with classic cp files to new folder. Running with cron every 24 hours and backuped with rsnapshot to another backup server will be enough.
    Because cp command will overwrite older files with new one, I do not need mtime to clear older one, and because files are so small in size, I do not need gziped.
    Of course that I have hard time to chown script, and also edit eol to unix... new staff for me, but google answered me

    In case that anyone need, this is my "bash script" to copy important (for me) conf and ini files, to have it just in case.

    Code:
    #!/bin/bash
    /bin/cp /etc/logrotate.conf /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /usr/local/lib/php.ini /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /etc/my.cnf /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /etc/redis.conf /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /etc/redis-sentinel.conf /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /etc/centminmod/custom_config.inc /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /etc/centminmod/php.d/zendopcache.ini /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /etc/centminmod/php.d/zzz_customphp.ini /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /etc/csf/csf.conf /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /etc/elasticsearch/elasticsearch.yml /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /etc/logwatch/conf/logwatch.conf /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /usr/local/etc/php-fpm.conf /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /usr/local/nginx/conf/nginx.conf /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /usr/local/nginx/conf/php.conf /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /usr/local/nginx/conf/drop.conf /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /usr/local/nginx/conf/staticfiles.conf /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /usr/local/nginx/conf/conf.d/virtual.conf /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /usr/local/nginx/conf/conf.d/ssl.conf /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /usr/local/nginx/conf/conf.d/pijanitvor.com.ssl.conf /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /usr/local/nginx/conf/brotli_inc.conf /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /usr/local/nginx/conf/maintenance.conf /home/nginx/domains/pijanitvor.com/backup/conf_backup
    /bin/cp /usr/local/nginx/conf/php-rediscache.conf /home/nginx/domains/pijanitvor.com/backup/conf_backup