bashThis shell script is to check weekly and monthly backup date. I use it to check backup status for cpanel account.  It can also be used to check daily backup. Combine with cronjob, you can create an email report. As for me, I have created cronjob to generate a report every Tuesday.

The shell script as below, and it is a very simple script. I name the script as ‘check-backup.sh’

#!/bin/bash
location1=/backup/weekly/*/accounts/
location2=/backup/monthly/*/accounts/
#Remove comment to enable daily backup check
#location3=/backup/daily/*/accounts/
location4=/backup/cpbackup/weekly/
location5=/backup/cpbackup/monthly/

echo "Total Cpanel account : "
find /var/cpanel/users -type f -print | wc -l

echo "Backup disk usage : "
df -h /backup

echo "Calculate number of weekly backup : "
ls -1 $location1*.tar.gz | wc -l

echo "Calculate number of monthly backup : "
ls -1 $location2*.tar.gz | wc -l

echo "Calculate number of legacy weekly backup : "
ls -1 $location4*.tar.gz | wc -l

echo "Calculate number of legacy monthly backup : "
ls -1 $location5*.tar.gz | wc -l



#Remove comment to enable daily backup check
# echo "Calculate number of daily backup : "
# ls -1 $location3*.tar.gz | wc -l

echo "List latest weekly backup"
ls -lath $location1*.tar.gz

echo "List latest monthly backup"
ls -lath $location2*.tar.gz

echo "List latest legacy weekly backup"
ls -lath $location4*.tar.gz

echo "List latest legacy monthly backup"
ls -lath $location5*.tar.gz



#Remove comment to enable daily backup check
# echo "List latest monthly backup"
# ls -lath $location3*.tar.gz



The output of the script will be similar like;

[email protected] [/backup]# ./check-backup.sh
Total Cpanel account :
90
Calculate number of weekly backup :
38
Calculate number of monthly backup :
42
Calculate number of legacy weekly backup :
50
Calculate number of legacy monthly backup :
ls: cannot access /backup/cpbackup/monthly/*.tar.gz: No such file or directory
0
List latest weekly backup
-rw------- 1 root root 0 May 11 12:09 /backup/weekly/2021-05-08/accounts/ver.tar.gz
-rw------- 1 root root 11G May 11 12:05 /backup/weekly/2021-05-08/accounts/rft.tar.gz
-rw------- 1 root root 131M May 11 11:25 /backup/weekly/2021-05-08/accounts/yos.tar.gz
-rw------- 1 root root 600M May 11 11:19 /backup/weekly/2021-05-08/accounts/kha.tar.gz
-rw------- 1 root root 1.6G May 11 11:10 /backup/weekly/2021-05-08/accounts/eco.tar.gz
-rw------- 1 root root 1.3G May 11 11:01 /backup/weekly/2021-05-08/accounts/sig.tar.gz
-rw------- 1 root root 371M May 11 10:44 /backup/weekly/2021-05-08/accounts/csg.tar.gz
-rw------- 1 root root 3.7G May 11 10:40 /backup/weekly/2021-05-08/accounts/swe.tar.gz
-rw------- 1 root root 3.1G May 11 10:15 /backup/weekly/2021-05-08/accounts/ler.tar.gz
-rw------- 1 root root 265M May 11 09:58 /backup/weekly/2021-05-08/accounts/blo.tar.gz
-rw------- 1 root root 164M May 11 09:54 /backup/weekly/2021-05-08/accounts/mus.tar.gz
-rw------- 1 root root 37G May 11 08:48 /backup/weekly/2021-05-08/accounts/ter.tar.gz
-rw------- 1 root root 5.4G May 9 12:06 /backup/weekly/2021-05-08/accounts/nor.tar.gz
-rw------- 1 root root 36M May 9 11:09 /backup/weekly/2021-05-08/accounts/lov.tar.gz
-rw------- 1 root root 1.9G May 9 11:08 /backup/weekly/2021-05-08/accounts/drj.tar.gz
-rw------- 1 root root 128M May 9 11:02 /backup/weekly/2021-05-08/accounts/pan.tar.gz
-rw------- 1 root root 3.5G May 9 10:56 /backup/weekly/2021-05-08/accounts/mar.tar.gz
-rw------- 1 root root 137M May 9 10:32 /backup/weekly/2021-05-08/accounts/can.tar.gz
-rw------- 1 root root 1.5G May 9 10:28 /backup/weekly/2021-05-08/accounts/myx.tar.gz
-rw------- 1 root root 4.4G May 9 10:19 /backup/weekly/2021-05-08/accounts/ric.tar.gz
-rw------- 1 root root 152M May 9 09:36 /backup/weekly/2021-05-08/accounts/paf.tar.gz
-rw------- 1 root root 821M May 9 09:33 /backup/weekly/2021-05-08/accounts/ros.tar.gz
-rw------- 1 root root 154M May 9 09:02 /backup/weekly/2021-05-08/accounts/asi.tar.gz
-rw------- 1 root root 5.6G May 9 08:57 /backup/weekly/2021-05-08/accounts/emi.tar.gz
-rw------- 1 root root 2.0G May 9 08:18 /backup/weekly/2021-05-08/accounts/tac.tar.gz
-rw------- 1 root root 230M May 9 07:33 /backup/weekly/2021-05-08/accounts/lor.tar.gz
-rw------- 1 root root 1.6G May 9 07:27 /backup/weekly/2021-05-08/accounts/mem.tar.gz
-rw------- 1 root root 558M May 9 06:31 /backup/weekly/2021-05-08/accounts/pen.tar.gz
-rw------- 1 root root 3.2G May 9 06:16 /backup/weekly/2021-05-08/accounts/dar.tar.gz
-rw------- 1 root root 13G May 8 11:33 /backup/weekly/2021-05-08/accounts/lit.tar.gz
-rw------- 1 root root 1.6G May 8 10:19 /backup/weekly/2021-05-08/accounts/tre.tar.gz
-rw------- 1 root root 2.1G May 8 10:03 /backup/weekly/2021-05-08/accounts/sya.tar.gz
-rw------- 1 root root 581M May 8 09:52 /backup/weekly/2021-05-08/accounts/cor.tar.gz
-rw------- 1 root root 2.5G May 8 09:43 /backup/weekly/2021-05-08/accounts/lan.tar.gz
-rw------- 1 root root 3.7G May 8 09:32 /backup/weekly/2021-05-08/accounts/mkb.tar.gz
-rw------- 1 root root 3.1G May 8 09:14 /backup/weekly/2021-05-08/accounts/ppm.tar.gz
-rw------- 1 root root 6.4G May 8 09:04 /backup/weekly/2021-05-08/accounts/alm.tar.gz
-rw------- 1 root root 8.6G May 8 08:38 /backup/weekly/2021-05-08/accounts/top.tar.gz
List latest monthly backup
-rw------- 1 root root 2.1G Jun 1 13:33 /backup/monthly/2021-06-01/accounts/tac.tar.gz
-rw------- 1 root root 37G Jun 1 12:06 /backup/monthly/2021-06-01/accounts/ter.tar.gz
-rw------- 1 root root 2.7G Jun 1 11:11 /backup/monthly/2021-06-01/accounts/wor.tar.gz
-rw------- 1 root root 900M Jun 1 10:57 /backup/monthly/2021-06-01/accounts/sta.tar.gz
-rw------- 1 root root 5.5G Jun 1 10:51 /backup/monthly/2021-06-01/accounts/nor.tar.gz
-rw------- 1 root root 3.2G Jun 1 10:27 /backup/monthly/2021-06-01/accounts/ler.tar.gz
-rw------- 1 root root 995M Jun 1 10:09 /backup/monthly/2021-06-01/accounts/pro.tar.gz
-rw------- 1 root root 1.8G Jun 1 10:04 /backup/monthly/2021-06-01/accounts/cel.tar.gz
-rw------- 1 root root 13G Jun 1 09:47 /backup/monthly/2021-06-01/accounts/lit.tar.gz
-rw------- 1 root root 2.5G Jun 1 09:16 /backup/monthly/2021-06-01/accounts/lan.tar.gz
-rw------- 1 root root 144M Jun 1 09:11 /backup/monthly/2021-06-01/accounts/can.tar.gz
-rw------- 1 root root 422M Jun 1 09:10 /backup/monthly/2021-06-01/accounts/cry.tar.gz
-rw------- 1 root root 3.0G Jun 1 09:07 /backup/monthly/2021-06-01/accounts/myx.tar.gz
-rw------- 1 root root 6.4G Jun 1 08:50 /backup/monthly/2021-06-01/accounts/ser.tar.gz
-rw------- 1 root root 558M Jun 1 08:32 /backup/monthly/2021-06-01/accounts/wel.tar.gz
-rw------- 1 root root 8.2G Jun 1 08:25 /backup/monthly/2021-06-01/accounts/qua.tar.gz
-rw------- 1 root root 1.5G Jun 1 08:14 /backup/monthly/2021-06-01/accounts/dec.tar.gz
-rw------- 1 root root 1.7G Jun 1 08:08 /backup/monthly/2021-06-01/accounts/tas.tar.gz
-rw------- 1 root root 40M Jun 1 08:04 /backup/monthly/2021-06-01/accounts/lov.tar.gz
-rw------- 1 root root 3.4G Jun 1 08:02 /backup/monthly/2021-06-01/accounts/dar.tar.gz
-rw------- 1 root root 1.1M Jun 1 07:39 /backup/monthly/2021-06-01/accounts/tap.tar.gz
-rw------- 1 root root 1.6G Jun 1 07:39 /backup/monthly/2021-06-01/accounts/eco.tar.gz
-rw------- 1 root root 647M Jun 1 07:35 /backup/monthly/2021-06-01/accounts/cor.tar.gz
-rw------- 1 root root 79M Jun 1 07:29 /backup/monthly/2021-06-01/accounts/kad.tar.gz
-rw------- 1 root root 23G Jun 1 07:12 /backup/monthly/2021-06-01/accounts/bio.tar.gz
-rw------- 1 root root 269M Jun 1 04:51 /backup/monthly/2021-06-01/accounts/ppm.tar.gz
-rw------- 1 root root 1.1G Jun 1 04:46 /backup/monthly/2021-06-01/accounts/hap.tar.gz
-rw------- 1 root root 1.1G Jun 1 04:35 /backup/monthly/2021-06-01/accounts/ros.tar.gz
-rw------- 1 root root 623M Jun 1 03:47 /backup/monthly/2021-06-01/accounts/kha.tar.gz
-rw------- 1 root root 2.1G Jun 1 03:32 /backup/monthly/2021-06-01/accounts/per.tar.gz
-rw------- 1 root root 1.1G Jun 1 03:21 /backup/monthly/2021-06-01/accounts/man.tar.gz
-rw------- 1 root root 1.4G Jun 1 03:06 /backup/monthly/2021-06-01/accounts/drb.tar.gz
-rw------- 1 root root 294M Jun 1 02:59 /backup/monthly/2021-06-01/accounts/blo.tar.gz
-rw------- 1 root root 23G Jun 1 02:44 /backup/monthly/2021-06-01/accounts/nak.tar.gz
-rw------- 1 root root 4.0G Jun 1 02:14 /backup/monthly/2021-06-01/accounts/uru.tar.gz
-rw------- 1 root root 50M Jun 1 01:52 /backup/monthly/2021-06-01/accounts/pkp.tar.gz
-rw------- 1 root root 3.6G Jun 1 01:50 /backup/monthly/2021-06-01/accounts/mar.tar.gz
-rw------- 1 root root 11G Jun 1 01:34 /backup/monthly/2021-06-01/accounts/rft.tar.gz
-rw------- 1 root root 5.8G Jun 1 01:21 /backup/monthly/2021-06-01/accounts/con.tar.gz
-rw------- 1 root root 1.9G Jun 1 01:11 /backup/monthly/2021-06-01/accounts/pak.tar.gz
-rw------- 1 root root 169M Jun 1 01:03 /backup/monthly/2021-06-01/accounts/mus.tar.gz
-rw------- 1 root root 469M Jun 1 01:00 /backup/monthly/2021-06-01/accounts/ski.tar.gz
List latest legacy weekly backup
-rw------- 1 root root  15G Jun  3 11:12 /backup/cpbackup/weekly/dam.tar.gz
-rw------- 1 root root 222M Jun  3 10:20 /backup/cpbackup/weekly/cre.tar.gz
-rw------- 1 root root  31G Jun  3 10:18 /backup/cpbackup/weekly/cre.tar.gz
-rw------- 1 root root 369M Jun  3 09:12 /backup/cpbackup/weekly/cor.tar.gz
-rw------- 1 root root 108M Jun  3 09:11 /backup/cpbackup/weekly/com.tar.gz
-rw------- 1 root root 3.8G Jun  3 09:10 /backup/cpbackup/weekly/cof.tar.gz
-rw------- 1 root root  12G Jun  3 09:00 /backup/cpbackup/weekly/cod.tar.gz
-rw------- 1 root root 9.6G Jun  3 08:20 /backup/cpbackup/weekly/cik.tar.gz
-rw------- 1 root root 130M Jun  3 07:56 /backup/cpbackup/weekly/cem.tar.gz
-rw------- 1 root root 3.9G Jun  3 07:55 /backup/cpbackup/weekly/cas.tar.gz
-rw------- 1 root root 4.4G Jun  3 07:47 /backup/cpbackup/weekly/car.tar.gz
-rw------- 1 root root 2.1G Jun  3 05:11 /backup/cpbackup/weekly/bve.tar.gz
-rw------- 1 root root 158M Jun  3 05:04 /backup/cpbackup/weekly/bro.tar.gz
-rw------- 1 root root  85M Jun  3 05:04 /backup/cpbackup/weekly/bod.tar.gz
-rw------- 1 root root 6.4G Jun  3 05:03 /backup/cpbackup/weekly/blu.tar.gz
-rw------- 1 root root 867M Jun  3 04:35 /backup/cpbackup/weekly/blu.tar.gz
-rw------- 1 root root 3.2G Jun  3 04:30 /backup/cpbackup/weekly/bkn.tar.gz
-rw------- 1 root root 2.9M Jun  3 04:18 /backup/cpbackup/weekly/bfo.tar.gz
-rw------- 1 root root 451M Jun  3 04:18 /backup/cpbackup/weekly/bfm.tar.gz
-rw------- 1 root root  41M Jun  3 04:16 /backup/cpbackup/weekly/bea.tar.gz
-rw------- 1 root root 8.1G Jun  3 04:16 /backup/cpbackup/weekly/bay.tar.gz
-rw------- 1 root root 993M Jun  3 03:48 /backup/cpbackup/weekly/bat.tar.gz
-rw------- 1 root root 100M Jun  3 03:44 /backup/cpbackup/weekly/bas.tar.gz
-rw------- 1 root root 6.1G Jun  3 03:44 /backup/cpbackup/weekly/bar.tar.gz
-rw------- 1 root root 101M Jun  3 03:12 /backup/cpbackup/weekly/bab.tar.gz
-rw------- 1 root root  21G Jun  3 03:12 /backup/cpbackup/weekly/azu.tar.gz
-rw------- 1 root root 361M Jun  3 02:29 /backup/cpbackup/weekly/axi.tar.gz
-rw------- 1 root root 619M Jun  3 02:26 /backup/cpbackup/weekly/axe.tar.gz
-rw------- 1 root root  85M Jun  3 02:19 /backup/cpbackup/weekly/ath.tar.gz
-rw------- 1 root root 706M Jun  3 02:18 /backup/cpbackup/weekly/asy.tar.gz
-rw------- 1 root root 2.8G Jun  3 02:11 /backup/cpbackup/weekly/arr.tar.gz
-rw------- 1 root root 5.7G Jun  3 01:58 /backup/cpbackup/weekly/arm.tar.gz
-rw------- 1 root root 6.7G Jun  3 01:45 /backup/cpbackup/weekly/aqu.tar.gz
-rw------- 1 root root 176M Jun  3 01:21 /backup/cpbackup/weekly/ape.tar.gz
-rw------- 1 root root 7.8G Jun  3 01:19 /backup/cpbackup/weekly/aod.tar.gz
-rw------- 1 root root 485M Jun  3 00:55 /backup/cpbackup/weekly/anz.tar.gz
-rw------- 1 root root 1.6G Jun  3 00:44 /backup/cpbackup/weekly/ann.tar.gz
-rw------- 1 root root 3.4G Jun  3 00:31 /backup/cpbackup/weekly/ang.tar.gz
-rw------- 1 root root 4.3G Jun  3 00:18 /backup/cpbackup/weekly/ang.tar.gz
-rw------- 1 root root 3.9G Jun  2 23:54 /backup/cpbackup/weekly/ane.tar.gz
-rw------- 1 root root 369M Jun  2 23:40 /backup/cpbackup/weekly/and.tar.gz
-rw------- 1 root root 4.9G Jun  2 23:35 /backup/cpbackup/weekly/ame.tar.gz
-rw------- 1 root root  46G Jun  2 22:58 /backup/cpbackup/weekly/amd.tar.gz
-rw------- 1 root root 2.0G Jun  2 20:31 /backup/cpbackup/weekly/all.tar.gz
-rw------- 1 root root 2.1G Jun  2 20:23 /backup/cpbackup/weekly/alh.tar.gz
-rw------- 1 root root 1.4G Jun  2 20:14 /backup/cpbackup/weekly/alb.tar.gz
-rw------- 1 root root  27G Jun  2 20:09 /backup/cpbackup/weekly/ajw.tar.gz
-rw------- 1 root root 8.2G Jun  2 18:39 /backup/cpbackup/weekly/ahm.tar.gz
-rw------- 1 root root 1.1G Jun  2 18:15 /backup/cpbackup/weekly/aer.tar.gz
-rw------- 1 root root 164M Jun  2 18:09 /backup/cpbackup/weekly/ada.tar.gz
List latest legacy monthly backup
ls: cannot access /backup/cpbackup/monthly/*.tar.gz: No such file or directory

And cronjob set as below;

0 0 * * 2 /backup/check-backup.sh | mail -s "Backup Server19" [email protected]

 

Leave a Reply

Your email address will not be published.

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.