I have a simple shell script that copies a folder, zips it, then deletes the original folder.
#!/bin/bash
today=$(date %m-%d-%Y)
cp -R /data /perf_backup/
/bin/zip -r data-"$today".zip data
rm -rf data
Works fine when I manually run it. The end result is a single zip file as expected.
However when cron job runs, only the initial data directory is there. As if everything after the initial folder copy is ignored.
Crontab is simply
* * * * 1-5 /opt/backup_data_folder.sh
This is on Oracle Linux Server 7.9 (ie CentOS)
CodePudding user response:
#!/bin/bash
today=$(date %m-%d-%Y)
cd /perf_backup/
cp -R /data ./data_backup
zip -r data-"$today".zip data_backup
rm -rf data_backup