Wildcards expand file names in lexicographic order. Since your date format matches lexicographic order, your requirement boils down to retaining the last X matches for a wildcard (or all matches if there are fewer than X). I'll assume that your backups are the files matching $device.*, adjust the pattern as needed.
In zsh:
set -- $device.*
if [[ $# -gt $X ]]; then set -- $@{[-$X,-1]}; fi
cp -- $@ /retain/area/
In any Bourne-style shell (ash, bash, ksh, …):
set -- "$device".*
if [ $# -gt $X ]; then shift $(($#-$X)); fi
cp -- "$@" /retain/area
If what you want is in fact to remove older files, you need to act on the first matches but X (or no matches if there are fewer than X).
In zsh:
files=($device.*)
rm -f -- $files[1,-$X-1]
In other shells:
set -- "$device".*
while [ $# -gt $X ]; do
rm -- "$1"
shift
done