In my Opinion, this will be the best solution for your requirments:
<?php
// Constans to Define
$active_dir = "pdfs/"; // Directory where your files are stored * WITH ENDING "/"
$backup_dir = "pdfs_backup/"; // Directory where the files should be moved to backup * WITH ENDING "/"
$backup_time_str = "Y"; // "Y" will backup in yearly folder structure (ex 2019), "Y-m" will backup in monthly folder (ex 2019-01), "Y-m-d" will back up in daily folder (ex 2019-01-05)
$min_file_age = time()-(3600*24*365); // only BackUp files older than actual time minus seconds (In this Case 1 Year)
// Start BackUp
backup_files_by_time($active_dir,$backup_dir,$min_file_age,$backup_time_str);
// BackUp Function
function backup_files_by_time($active_dir,$backup_dir,$min_file_age,$backup_time_str="Y") {
$pdf_arr = scandir($active_dir);
foreach($pdf_arr as $file) {
if(file_exists($active_dir.$file)) {
$filetime = filemtime($active_dir.$file);
// File is supposed to be backuped
if ($filetime<$min_file_age) {
// Create Folder if not exists
if (!is_dir($backup_dir.date($backup_time_str,$filetime))) {mkdir($backup_dir.date($backup_time_str,$filetime));}
// Moving File to Backupfolder
rename($active_dir.$file,$backup_dir.date($backup_time_str,$filetime)."/".$file);
}
}
}
}
?>