I have a folder called statistics
in an Ubuntu server in which data files are regularly stored. How can I rename statistics
folder to backup-xx
while re-creating statistics
folder to be available for storing new files?
The files in statistics
folder is created by PHP file_put_contents
.
I prefer renaming the folder, as there are many files in the statistics
folder.
mv statistics backup-xx && mkdir statistics
This would rename the existing statistics
directory to backup-xx
, and if that succeeds it would carry on to create a new statistics
directory.
For a more atomic operation, consider creating a directory statistics-001
(or similar, maybe by replacing 001
with today's date in a suitable format), and a symbolic link to it called statistics
:
mkdir statistics-001
ln -s statistics-001 statistics
When you want to "rotate" this so that new data goes into a clean directory, create the directory first, then recreate the statistics
link to it:
mkdir statistics-002
ln -sf statistics-002 statistics
mv statistics-001 backup-001
This way, any program writing to the statistics
directory (i.e. the directory that this symbolic link points to) will never1 fail to find it.
If you need special permissions or ownership set on the directory that statistics
points to, set these before (re-)creating the link.
1Or rather, this way, the time that a program would be without a valid target directory is minimized as much as practically possible using standard Unix tools.
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句