I've bumped into situation the other days related to removing archived log files not needed for recovery from the backup. After making backup by pg_basebackup, the pg_archivecleanup command was used like of :
$ pg_archivecleanup -d -n -x .gz /arch/archive 000000010000005C000000ED.00000028.backup
The response was :
$ pg_archivecleanup: keeping WAL file "/arch/archive/000000010000005C000000ED" and later
And nothing happened more. The directory /arch/archive contained 24k files, but pg_archivecleanup haven't considered them at all.
The culprit of such behavior - a prefix in archive wal filenames. Their names included 'archive' prefix, and pg_archivecleanup expects they didn't :
archive000000010000005E000000D6.gz
archive000000010000005E000000D5.gz
archive000000010000005E000000D4.gz
archive000000010000005E000000D3.gz
archive000000010000005E000000D2.gz
archive000000010000005E000000D1.gz
archive000000010000005E000000D0.gz
archive000000010000005E000000CF.gz
archive000000010000005E000000CE.gz
To make cleanup you'd better to rename them :
% cd ${archive_dir} && find -type f -name "archive*" -exec rename archive "" '{}' \;
After that the cleanup worked as expected :
$ pg_archivecleanup -d -n -x .gz /arch/archive 000000010000005C000000ED.00000028.backup
dry run cleanup execution :
pg_archivecleanup: keeping WAL file "/arch/archive/000000010000005C000000ED" and later
/arch/archive/000000010000001000000080.gz
pg_archivecleanup: file "/arch/archive/000000010000001000000080.gz" would be removed
/arch/archive/000000010000000100000029.gz
pg_archivecleanup: file "/arch/archive/000000010000000100000029.gz" would be removed
/arch/archive/00000001000000500000003D.gz
...
P.S. When -x switch is used, then compressed (and uncompressed as well) wal archived files are considered for removing.
That's it ! Good Luck !