There are a lot of things that help me to stay motivated, but first and foremost - it's the people around you. I don't think I ever went through a day at ILM and didn't laugh. It doesn't matter how tedious a shot or project can be, the atmosphere is always fun and everybody around you is there for support. You know that you're not alone.
I also listen to a lot of music and movies while I work. Usually I pick movies that I'm very familiar with so it's not distracting me from the actual work, but it provides a comfortable and pleasant background noise. Usually they are movies from my childhood, like the classic Star Wars trilogy, or Back to the Future, The Goonies, Big Trouble in Little China, etc.
Since our projects usually only last a few months and not years, a long project is never really that long. It might feel like it, but there's always a next project lined up that you can look forward to. And if all of that fails, you just have to remind yourself that no matter what, it is your job to do the best you can, so suck it up and be professional. :)