Jayreis
Jayreis

Reputation: 287

creating site backups via command line

I have a php script that is run via cron whose purpose is to tar up an entire directory. However my issue is it seems to just be creating an empty tar file??

 exec("tar -zcvf abcd.com-dir-".date('Y-m-d').".tar.gz var/www/html/abcd.com");

I confirmed the full path to the website is var/www/html/abcd.com

any other suggestions on what might be causing the code to just create an empty .tar.gz file?

Upvotes: 1

Views: 68

Answers (1)

Felippe Duarte
Felippe Duarte

Reputation: 15131

You forgot the first slash in /var...

So, you can use

exec("tar -zcvf abcd.com-dir-".date('Y-m-d').".tar.gz /var/www/html/abcd.com");

Or, you can just add the command directly, without the need of PHP

tar -zcvf abcd.com-dir-$(date +%Y-%m-%d).tar.gz /var/www/html/abcd.com

Upvotes: 2

Related Questions